summaryrefslogtreecommitdiff
path: root/cppu/source/threadpool
diff options
context:
space:
mode:
Diffstat (limited to 'cppu/source/threadpool')
-rw-r--r--cppu/source/threadpool/current.cxx4
-rw-r--r--cppu/source/threadpool/jobqueue.cxx3
-rw-r--r--cppu/source/threadpool/jobqueue.hxx6
-rw-r--r--cppu/source/threadpool/thread.cxx32
-rw-r--r--cppu/source/threadpool/thread.hxx5
-rw-r--r--cppu/source/threadpool/threadpool.cxx58
-rw-r--r--cppu/source/threadpool/threadpool.hxx15
7 files changed, 74 insertions, 49 deletions
diff --git a/cppu/source/threadpool/current.cxx b/cppu/source/threadpool/current.cxx
index 07323c2fd..805b5759a 100644
--- a/cppu/source/threadpool/current.cxx
+++ b/cppu/source/threadpool/current.cxx
@@ -106,11 +106,9 @@ static typelib_InterfaceTypeDescription * get_type_XCurrentContext()
1, aParameters, 1, pExceptions );
typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
typelib_typedescription_release( (typelib_TypeDescription*)pMethod );
-#if ! defined CPPU_LEAK_STATIC_DATA
- // another static ref
+ // another static ref:
++reinterpret_cast< typelib_TypeDescription * >( pTD )->
nStaticRefCount;
-#endif
s_type_XCurrentContext = pTD;
}
}
diff --git a/cppu/source/threadpool/jobqueue.cxx b/cppu/source/threadpool/jobqueue.cxx
index 18693bef1..4f83261c9 100644
--- a/cppu/source/threadpool/jobqueue.cxx
+++ b/cppu/source/threadpool/jobqueue.cxx
@@ -42,6 +42,7 @@ namespace cppu_threadpool {
m_cndWait( osl_createCondition() )
{
osl_resetCondition( m_cndWait );
+ m_DisposedCallerAdmin = DisposedCallerAdmin::getInstance();
}
JobQueue::~JobQueue()
@@ -68,7 +69,7 @@ namespace cppu_threadpool {
{
// synchronize with the dispose calls
MutexGuard guard( m_mutex );
- if( DisposedCallerAdmin::getInstance()->isDisposed( nDisposeId ) )
+ if( m_DisposedCallerAdmin->isDisposed( nDisposeId ) )
{
return 0;
}
diff --git a/cppu/source/threadpool/jobqueue.hxx b/cppu/source/threadpool/jobqueue.hxx
index 7a50b8a0e..31ea0690e 100644
--- a/cppu/source/threadpool/jobqueue.hxx
+++ b/cppu/source/threadpool/jobqueue.hxx
@@ -34,6 +34,8 @@
#include <osl/conditn.h>
#include <osl/mutex.hxx>
+#include <boost/shared_ptr.hpp>
+
namespace cppu_threadpool
{
extern "C" typedef void (SAL_CALL RequestFun)(void *);
@@ -48,6 +50,9 @@ namespace cppu_threadpool
typedef ::std::list < sal_Int64 > CallStackList;
+ class DisposedCallerAdmin;
+ typedef boost::shared_ptr<DisposedCallerAdmin> DisposedCallerAdminHolder;
+
class JobQueue
{
public:
@@ -73,6 +78,7 @@ namespace cppu_threadpool
sal_Int32 m_nToDo;
sal_Bool m_bSuspended;
oslCondition m_cndWait;
+ DisposedCallerAdminHolder m_DisposedCallerAdmin;
};
}
diff --git a/cppu/source/threadpool/thread.cxx b/cppu/source/threadpool/thread.cxx
index 565020850..f8e12a0aa 100644
--- a/cppu/source/threadpool/thread.cxx
+++ b/cppu/source/threadpool/thread.cxx
@@ -31,6 +31,8 @@
#include <osl/diagnose.h>
#include <uno/threadpool.h>
+#include <rtl/instance.hxx>
+
#include "thread.hxx"
#include "jobqueue.hxx"
#include "threadpool.hxx"
@@ -98,20 +100,17 @@ namespace cppu_threadpool {
} while( pCurrent );
}
- ThreadAdmin* ThreadAdmin::getInstance()
+ struct theThreadAdmin : public rtl::StaticWithInit< ThreadAdminHolder, theThreadAdmin >
{
- static ThreadAdmin *pThreadAdmin = 0;
- if( ! pThreadAdmin )
- {
- MutexGuard guard( Mutex::getGlobalMutex() );
- if( ! pThreadAdmin )
- {
- static ThreadAdmin admin;
- pThreadAdmin = &admin;
- }
+ ThreadAdminHolder operator () () {
+ ThreadAdminHolder aRet(new ThreadAdmin());
+ return aRet;
}
- return pThreadAdmin;
+ };
+ ThreadAdminHolder& ThreadAdmin::getInstance()
+ {
+ return theThreadAdmin::get();
}
// ----------------------------------------------------------------------------------
@@ -119,12 +118,13 @@ namespace cppu_threadpool {
const ByteSequence &aThreadId,
sal_Bool bAsynchron )
: m_thread( 0 )
+ , m_aThreadAdmin( ThreadAdmin::getInstance() )
, m_pQueue( pQueue )
, m_aThreadId( aThreadId )
, m_bAsynchron( bAsynchron )
, m_bDeleteSelf( sal_True )
{
- ThreadAdmin::getInstance()->add( this );
+ m_aThreadAdmin->add( this );
}
@@ -166,7 +166,7 @@ namespace cppu_threadpool {
void ORequestThread::onTerminated()
{
- ThreadAdmin::getInstance()->remove( this );
+ m_aThreadAdmin->remove( this );
if( m_bDeleteSelf )
{
delete this;
@@ -175,6 +175,8 @@ namespace cppu_threadpool {
void ORequestThread::run()
{
+ ThreadPoolHolder theThreadPool = cppu_threadpool::ThreadPool::getInstance();
+
while ( m_pQueue )
{
if( ! m_bAsynchron )
@@ -197,7 +199,7 @@ namespace cppu_threadpool {
if( m_pQueue->isEmpty() )
{
- ThreadPool::getInstance()->revokeQueue( m_aThreadId , m_bAsynchron );
+ theThreadPool->revokeQueue( m_aThreadId , m_bAsynchron );
// Note : revokeQueue might have failed because m_pQueue.isEmpty()
// may be false (race).
}
@@ -211,7 +213,7 @@ namespace cppu_threadpool {
uno_releaseIdFromCurrentThread();
}
- cppu_threadpool::ThreadPool::getInstance()->waitInPool( this );
+ theThreadPool->waitInPool( this );
}
}
}
diff --git a/cppu/source/threadpool/thread.hxx b/cppu/source/threadpool/thread.hxx
index 642820e9e..becf50286 100644
--- a/cppu/source/threadpool/thread.hxx
+++ b/cppu/source/threadpool/thread.hxx
@@ -37,6 +37,8 @@
namespace cppu_threadpool {
class JobQueue;
+ class ThreadAdmin;
+ typedef boost::shared_ptr<ThreadAdmin> ThreadAdminHolder;
//-----------------------------------------
// private thread class for the threadpool
@@ -61,6 +63,7 @@ namespace cppu_threadpool {
private:
oslThread m_thread;
+ ThreadAdminHolder m_aThreadAdmin;
JobQueue *m_pQueue;
::rtl::ByteSequence m_aThreadId;
sal_Bool m_bAsynchron;
@@ -71,7 +74,7 @@ namespace cppu_threadpool {
{
public:
~ThreadAdmin ();
- static ThreadAdmin *getInstance();
+ static ThreadAdminHolder &getInstance();
void add( ORequestThread * );
void remove( ORequestThread * );
void join();
diff --git a/cppu/source/threadpool/threadpool.cxx b/cppu/source/threadpool/threadpool.cxx
index f09c8fbd3..6093c44c7 100644
--- a/cppu/source/threadpool/threadpool.cxx
+++ b/cppu/source/threadpool/threadpool.cxx
@@ -33,6 +33,7 @@
#include <osl/diagnose.h>
#include <osl/mutex.hxx>
#include <osl/thread.h>
+#include <rtl/instance.hxx>
#include <uno/threadpool.h>
@@ -44,19 +45,17 @@ using namespace ::osl;
namespace cppu_threadpool
{
- DisposedCallerAdmin *DisposedCallerAdmin::getInstance()
+ struct theDisposedCallerAdmin :
+ public rtl::StaticWithInit< DisposedCallerAdminHolder, theDisposedCallerAdmin >
{
- static DisposedCallerAdmin *pDisposedCallerAdmin = 0;
- if( ! pDisposedCallerAdmin )
- {
- MutexGuard guard( Mutex::getGlobalMutex() );
- if( ! pDisposedCallerAdmin )
- {
- static DisposedCallerAdmin admin;
- pDisposedCallerAdmin = &admin;
- }
+ DisposedCallerAdminHolder operator () () {
+ return DisposedCallerAdminHolder(new DisposedCallerAdmin());
}
- return pDisposedCallerAdmin;
+ };
+
+ DisposedCallerAdminHolder DisposedCallerAdmin::getInstance()
+ {
+ return theDisposedCallerAdmin::get();
}
DisposedCallerAdmin::~DisposedCallerAdmin()
@@ -107,6 +106,21 @@ namespace cppu_threadpool
//-------------------------------------------------------------------------------
+
+ struct theThreadPool :
+ public rtl::StaticWithInit< ThreadPoolHolder, theThreadPool >
+ {
+ ThreadPoolHolder operator () () {
+ ThreadPoolHolder aRet(new ThreadPool());
+ return aRet;
+ }
+ };
+
+ ThreadPool::ThreadPool()
+ {
+ m_DisposedCallerAdmin = DisposedCallerAdmin::getInstance();
+ }
+
ThreadPool::~ThreadPool()
{
#if OSL_DEBUG_LEVEL > 1
@@ -116,19 +130,9 @@ namespace cppu_threadpool
}
#endif
}
- ThreadPool *ThreadPool::getInstance()
+ ThreadPoolHolder ThreadPool::getInstance()
{
- static ThreadPool *pThreadPool = 0;
- if( ! pThreadPool )
- {
- MutexGuard guard( Mutex::getGlobalMutex() );
- if( ! pThreadPool )
- {
- static ThreadPool pool;
- pThreadPool = &pool;
- }
- }
- return pThreadPool;
+ return theThreadPool::get();
}
@@ -136,7 +140,7 @@ namespace cppu_threadpool
{
if( nDisposeId )
{
- DisposedCallerAdmin::getInstance()->dispose( nDisposeId );
+ m_DisposedCallerAdmin->dispose( nDisposeId );
MutexGuard guard( m_mutex );
for( ThreadIdHashMap::iterator ii = m_mapQueue.begin() ;
@@ -171,7 +175,7 @@ namespace cppu_threadpool
void ThreadPool::stopDisposing( sal_Int64 nDisposeId )
{
- DisposedCallerAdmin::getInstance()->stopDisposing( nDisposeId );
+ m_DisposedCallerAdmin->stopDisposing( nDisposeId );
}
/******************
@@ -400,7 +404,7 @@ struct uno_ThreadPool_Hash
-typedef ::std::hash_set< uno_ThreadPool, uno_ThreadPool_Hash, uno_ThreadPool_Equal > ThreadpoolHashSet;
+typedef ::std::hash_map< uno_ThreadPool, ThreadPoolHolder, uno_ThreadPool_Hash, uno_ThreadPool_Equal > ThreadpoolHashSet;
static ThreadpoolHashSet *g_pThreadpoolHashSet;
@@ -420,7 +424,7 @@ uno_threadpool_create() SAL_THROW_EXTERN_C()
// Just ensure that the handle is unique in the process (via heap)
uno_ThreadPool h = new struct _uno_ThreadPool;
- g_pThreadpoolHashSet->insert( h );
+ g_pThreadpoolHashSet->insert( ThreadpoolHashSet::value_type(h, ThreadPool::getInstance()) );
return h;
}
diff --git a/cppu/source/threadpool/threadpool.hxx b/cppu/source/threadpool/threadpool.hxx
index 1ff1748fe..b9df49f43 100644
--- a/cppu/source/threadpool/threadpool.hxx
+++ b/cppu/source/threadpool/threadpool.hxx
@@ -30,6 +30,8 @@
#include <rtl/byteseq.hxx>
+#include <boost/shared_ptr.hpp>
+
#include "jobqueue.hxx"
@@ -75,13 +77,16 @@ namespace cppu_threadpool {
};
typedef ::std::list < struct ::cppu_threadpool::WaitingThread * > WaitingThreadList;
+
+ class DisposedCallerAdmin;
+ typedef boost::shared_ptr<DisposedCallerAdmin> DisposedCallerAdminHolder;
class DisposedCallerAdmin
{
public:
~DisposedCallerAdmin();
- static DisposedCallerAdmin *getInstance();
+ static DisposedCallerAdminHolder getInstance();
void dispose( sal_Int64 nDisposeId );
void stopDisposing( sal_Int64 nDisposeId );
@@ -92,11 +97,15 @@ namespace cppu_threadpool {
DisposedCallerList m_lst;
};
+ class ThreadPool;
+ typedef boost::shared_ptr<ThreadPool> ThreadPoolHolder;
+
class ThreadPool
{
public:
+ ThreadPool();
~ThreadPool();
- static ThreadPool *getInstance();
+ static ThreadPoolHolder getInstance();
void dispose( sal_Int64 nDisposeId );
void stopDisposing( sal_Int64 nDisposeId );
@@ -124,6 +133,8 @@ namespace cppu_threadpool {
::osl::Mutex m_mutexWaitingThreadList;
WaitingThreadList m_lstThreads;
+
+ DisposedCallerAdminHolder m_DisposedCallerAdmin;
};
} // end namespace cppu_threadpool