Model the dispose tokens as void const * instead of sal_Int64

...which avoids the sal_IntPtr casts

Change-Id: I518fcefc66d297b56c9bd94f7826a44715acb5f5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96392
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann 2020-06-15 19:41:37 +02:00
parent c87a978de4
commit d8feb7738d
5 changed files with 26 additions and 30 deletions

View file

@ -45,7 +45,7 @@ namespace cppu_threadpool {
m_nToDo ++;
}
void *JobQueue::enter( sal_Int64 nDisposeId , bool bReturnWhenNoJob )
void *JobQueue::enter( void const * nDisposeId , bool bReturnWhenNoJob )
{
void *pReturn = nullptr;
{
@ -77,7 +77,7 @@ namespace cppu_threadpool {
// synchronize with add and dispose calls
MutexGuard guard( m_mutex );
if( 0 == m_lstCallstack.front() )
if( nullptr == m_lstCallstack.front() )
{
// disposed !
if (!m_lstJob.empty() && m_lstJob.front().doRequest == nullptr) {
@ -89,7 +89,7 @@ namespace cppu_threadpool {
}
if( m_lstJob.empty()
&& (m_lstCallstack.empty()
|| m_lstCallstack.front() != 0) )
|| m_lstCallstack.front() != nullptr) )
{
m_cndWait.reset();
}
@ -103,7 +103,7 @@ namespace cppu_threadpool {
m_lstJob.pop_front();
}
if( m_lstJob.empty()
&& (m_lstCallstack.empty() || m_lstCallstack.front() != 0) )
&& (m_lstCallstack.empty() || m_lstCallstack.front() != nullptr) )
{
m_cndWait.reset();
}
@ -133,14 +133,14 @@ namespace cppu_threadpool {
return pReturn;
}
void JobQueue::dispose( sal_Int64 nDisposeId )
void JobQueue::dispose( void const * nDisposeId )
{
MutexGuard guard( m_mutex );
for( auto& rId : m_lstCallstack )
{
if( rId == nDisposeId )
{
rId = 0;
rId = nullptr;
}
}

View file

@ -47,8 +47,8 @@ namespace cppu_threadpool
void add( void *pThreadSpecificData, RequestFun * doRequest );
void *enter( sal_Int64 nDisposeId , bool bReturnWhenNoJob = false );
void dispose( sal_Int64 nDisposeId );
void *enter( void const * nDisposeId , bool bReturnWhenNoJob = false );
void dispose( void const * nDisposeId );
void suspend();
void resume();
@ -60,7 +60,7 @@ namespace cppu_threadpool
private:
mutable ::osl::Mutex m_mutex;
std::deque < struct Job > m_lstJob;
std::deque<sal_Int64> m_lstCallstack;
std::deque<void const *> m_lstCallstack;
sal_Int32 m_nToDo;
bool m_bSuspended;
osl::Condition m_cndWait;

View file

@ -163,8 +163,7 @@ namespace cppu_threadpool {
// It does not make sense to dispose a call in this state.
// That's way we put it a disposeid, that can't be used otherwise.
m_pQueue->enter(
sal::static_int_cast< sal_Int64 >(
reinterpret_cast< sal_IntPtr >(this)),
this,
true );
if( m_pQueue->isEmpty() )

View file

@ -66,19 +66,19 @@ namespace cppu_threadpool
SAL_WARN_IF( !m_vector.empty(), "cppu.threadpool", "DisposedCallerList : " << m_vector.size() << " left");
}
void DisposedCallerAdmin::dispose( sal_Int64 nDisposeId )
void DisposedCallerAdmin::dispose( void const * nDisposeId )
{
MutexGuard guard( m_mutex );
m_vector.push_back( nDisposeId );
}
void DisposedCallerAdmin::destroy( sal_Int64 nDisposeId )
void DisposedCallerAdmin::destroy( void const * nDisposeId )
{
MutexGuard guard( m_mutex );
m_vector.erase(std::remove(m_vector.begin(), m_vector.end(), nDisposeId), m_vector.end());
}
bool DisposedCallerAdmin::isDisposed( sal_Int64 nDisposeId )
bool DisposedCallerAdmin::isDisposed( void const * nDisposeId )
{
MutexGuard guard( m_mutex );
return (std::find(m_vector.begin(), m_vector.end(), nDisposeId) != m_vector.end());
@ -95,7 +95,7 @@ namespace cppu_threadpool
SAL_WARN_IF( m_mapQueue.size(), "cppu.threadpool", "ThreadIdHashMap: " << m_mapQueue.size() << " left");
}
void ThreadPool::dispose( sal_Int64 nDisposeId )
void ThreadPool::dispose( void const * nDisposeId )
{
m_DisposedCallerAdmin->dispose( nDisposeId );
@ -113,7 +113,7 @@ namespace cppu_threadpool
}
}
void ThreadPool::destroy( sal_Int64 nDisposeId )
void ThreadPool::destroy( void const * nDisposeId )
{
m_DisposedCallerAdmin->destroy( nDisposeId );
}
@ -296,7 +296,7 @@ namespace cppu_threadpool
}
}
void * ThreadPool::enter( const ByteSequence & aThreadId , sal_Int64 nDisposeId )
void * ThreadPool::enter( const ByteSequence & aThreadId , void const * nDisposeId )
{
JobQueue *pQueue = nullptr;
{
@ -415,8 +415,7 @@ uno_threadpool_enter( uno_ThreadPool hPool , void **ppJob )
*ppJob =
getThreadPool( hPool )->enter(
pThreadId,
sal::static_int_cast< sal_Int64 >(
reinterpret_cast< sal_IntPtr >(hPool)) );
hPool );
rtl_byte_sequence_release( pThreadId );
uno_releaseIdFromCurrentThread();
}
@ -447,8 +446,7 @@ extern "C" void SAL_CALL
uno_threadpool_dispose( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C()
{
getThreadPool(hPool)->dispose(
sal::static_int_cast< sal_Int64 >(
reinterpret_cast< sal_IntPtr >(hPool)) );
hPool );
}
extern "C" void SAL_CALL
@ -456,8 +454,7 @@ uno_threadpool_destroy( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C()
{
ThreadPoolHolder p( getThreadPool(hPool) );
p->destroy(
sal::static_int_cast< sal_Int64 >(
reinterpret_cast< sal_IntPtr >(hPool)) );
hPool );
bool empty;
{

View file

@ -84,13 +84,13 @@ namespace cppu_threadpool {
static DisposedCallerAdminHolder const & getInstance();
void dispose( sal_Int64 nDisposeId );
void destroy( sal_Int64 nDisposeId );
bool isDisposed( sal_Int64 nDisposeId );
void dispose( void const * nDisposeId );
void destroy( void const * nDisposeId );
bool isDisposed( void const * nDisposeId );
private:
::osl::Mutex m_mutex;
std::vector< sal_Int64 > m_vector;
std::vector< void const * > m_vector;
};
class ThreadAdmin
@ -120,8 +120,8 @@ namespace cppu_threadpool {
ThreadPool();
virtual ~ThreadPool() override;
void dispose( sal_Int64 nDisposeId );
void destroy( sal_Int64 nDisposeId );
void dispose( void const * nDisposeId );
void destroy( void const * nDisposeId );
bool addJob( const ::rtl::ByteSequence &aThreadId,
bool bAsynchron,
@ -129,7 +129,7 @@ namespace cppu_threadpool {
RequestFun * doRequest );
void prepare( const ::rtl::ByteSequence &aThreadId );
void * enter( const ::rtl::ByteSequence &aThreadId, sal_Int64 nDisposeId );
void * enter( const ::rtl::ByteSequence &aThreadId, void const * nDisposeId );
/********
* @return true, if queue could be successfully revoked.