diff options
author | Caolán McNamara <caolanm@redhat.com> | 2010-10-11 10:41:50 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2010-10-11 12:37:08 +0100 |
commit | 521a9f6f76a135928806355e981eeb7860b2fbe7 (patch) | |
tree | b28a92b9e74bb79afdaee0a046a2560efecf5fc1 /cppu/source/threadpool/threadpool.cxx | |
parent | 2f68ee59b2a2a35433925626fa4a155b68ddb6f7 (diff) |
#i107490# cppu lifecycle cleanup
Diffstat (limited to 'cppu/source/threadpool/threadpool.cxx')
-rw-r--r-- | cppu/source/threadpool/threadpool.cxx | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/cppu/source/threadpool/threadpool.cxx b/cppu/source/threadpool/threadpool.cxx index accf585957f8..3514d294192a 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; } |