diff options
author | Vladimir Glazunov <vg@openoffice.org> | 2010-10-01 16:02:03 +0200 |
---|---|---|
committer | Vladimir Glazunov <vg@openoffice.org> | 2010-10-01 16:02:03 +0200 |
commit | 1a4e94a77140a19d943a4c5fac3a65127debbc1e (patch) | |
tree | b53e0c4ae625b9752a87f97c01577808e7608aa8 /cppu/source/threadpool/thread.cxx | |
parent | 2ef5501f5d7740e453c3672665c11216b375b5f8 (diff) | |
parent | 5312f409180ab4e29598f674c60d32665a16bb9b (diff) |
#i10000#ooo/DEV300_m89
Diffstat (limited to 'cppu/source/threadpool/thread.cxx')
-rw-r--r-- | cppu/source/threadpool/thread.cxx | 32 |
1 files changed, 17 insertions, 15 deletions
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 ); } } } |