summaryrefslogtreecommitdiff
path: root/cppu/source/threadpool/threadpool.cxx
diff options
context:
space:
mode:
authorKurt Zenker <kz@openoffice.org>2006-04-26 19:50:31 +0000
committerKurt Zenker <kz@openoffice.org>2006-04-26 19:50:31 +0000
commitcaf3637b53e9642e8f7d81378b7701a65605f52f (patch)
treee487016e75a4fef5ae08572984d30eab10f88f49 /cppu/source/threadpool/threadpool.cxx
parent9799afcea2a59dfe5c3ee2a1a1ed9d9017fccde1 (diff)
INTEGRATION: CWS jsc9 (1.13.2); FILE MERGED
2006/04/26 14:15:33 jsc 1.13.2.1: #134738# move fixes back to previous version
Diffstat (limited to 'cppu/source/threadpool/threadpool.cxx')
-rw-r--r--cppu/source/threadpool/threadpool.cxx67
1 files changed, 43 insertions, 24 deletions
diff --git a/cppu/source/threadpool/threadpool.cxx b/cppu/source/threadpool/threadpool.cxx
index c628474dadd2..c08e37885eaf 100644
--- a/cppu/source/threadpool/threadpool.cxx
+++ b/cppu/source/threadpool/threadpool.cxx
@@ -4,9 +4,9 @@
*
* $RCSfile: threadpool.cxx,v $
*
- * $Revision: 1.13 $
+ * $Revision: 1.14 $
*
- * last change: $Author: hr $ $Date: 2006-04-19 13:49:32 $
+ * last change: $Author: kz $ $Date: 2006-04-26 20:50:31 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -49,6 +49,21 @@ using namespace ::osl;
namespace cppu_threadpool
{
+ DisposedCallerAdmin *DisposedCallerAdmin::getInstance()
+ {
+ static DisposedCallerAdmin *pDisposedCallerAdmin = 0;
+ if( ! pDisposedCallerAdmin )
+ {
+ MutexGuard guard( Mutex::getGlobalMutex() );
+ if( ! pDisposedCallerAdmin )
+ {
+ static DisposedCallerAdmin admin;
+ pDisposedCallerAdmin = &admin;
+ }
+ }
+ return pDisposedCallerAdmin;
+ }
+
DisposedCallerAdmin::~DisposedCallerAdmin()
{
#if OSL_DEBUG_LEVEL > 1
@@ -95,8 +110,8 @@ namespace cppu_threadpool
return sal_False;
}
- ThreadPool::ThreadPool() {}
+ //-------------------------------------------------------------------------------
ThreadPool::~ThreadPool()
{
#if OSL_DEBUG_LEVEL > 1
@@ -106,12 +121,27 @@ namespace cppu_threadpool
}
#endif
}
+ ThreadPool *ThreadPool::getInstance()
+ {
+ static ThreadPool *pThreadPool = 0;
+ if( ! pThreadPool )
+ {
+ MutexGuard guard( Mutex::getGlobalMutex() );
+ if( ! pThreadPool )
+ {
+ static ThreadPool pool;
+ pThreadPool = &pool;
+ }
+ }
+ return pThreadPool;
+ }
+
void ThreadPool::dispose( sal_Int64 nDisposeId )
{
if( nDisposeId )
{
- m_disposedCallerAdmin.dispose( nDisposeId );
+ DisposedCallerAdmin::getInstance()->dispose( nDisposeId );
MutexGuard guard( m_mutex );
for( ThreadIdHashMap::iterator ii = m_mapQueue.begin() ;
@@ -146,7 +176,7 @@ namespace cppu_threadpool
void ThreadPool::stopDisposing( sal_Int64 nDisposeId )
{
- m_disposedCallerAdmin.stopDisposing( nDisposeId );
+ DisposedCallerAdmin::getInstance()->stopDisposing( nDisposeId );
}
/******************
@@ -210,7 +240,7 @@ namespace cppu_threadpool
if( bCreate )
{
ORequestThread *pThread =
- new ORequestThread( this, pQueue , aThreadId, bAsynchron);
+ new ORequestThread( pQueue , aThreadId, bAsynchron);
// deletes itself !
pThread->create();
}
@@ -340,7 +370,7 @@ namespace cppu_threadpool
}
OSL_ASSERT( pQueue );
- void *pReturn = pQueue->enter( m_disposedCallerAdmin, nDisposeId );
+ void *pReturn = pQueue->enter( nDisposeId );
if( pQueue->isCallstackEmpty() )
{
@@ -377,8 +407,6 @@ struct uno_ThreadPool_Hash
typedef ::std::hash_set< uno_ThreadPool, uno_ThreadPool_Hash, uno_ThreadPool_Equal > ThreadpoolHashSet;
-static ThreadPool * g_threadPool;
-
static ThreadpoolHashSet *g_pThreadpoolHashSet;
struct _uno_ThreadPool
@@ -390,14 +418,6 @@ extern "C" uno_ThreadPool SAL_CALL
uno_threadpool_create() SAL_THROW_EXTERN_C()
{
MutexGuard guard( Mutex::getGlobalMutex() );
-
- //TODO: g_threadPool is accessed in other places without locking the global
- // mutex, so that the value set here might not be observed there:
- if (g_threadPool == 0) {
- g_threadPool = new ThreadPool;
- }
- g_threadPool->acquire();
-
if( ! g_pThreadpoolHashSet )
{
g_pThreadpoolHashSet = new ThreadpoolHashSet();
@@ -414,7 +434,7 @@ uno_threadpool_attach( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C()
{
sal_Sequence *pThreadId = 0;
uno_getIdOfCurrentThread( &pThreadId );
- g_threadPool->prepare( pThreadId );
+ ThreadPool::getInstance()->prepare( pThreadId );
rtl_byte_sequence_release( pThreadId );
uno_releaseIdFromCurrentThread();
}
@@ -425,7 +445,8 @@ uno_threadpool_enter( uno_ThreadPool hPool , void **ppJob )
{
sal_Sequence *pThreadId = 0;
uno_getIdOfCurrentThread( &pThreadId );
- *ppJob = g_threadPool->enter( pThreadId , (sal_Int64 ) hPool );
+ *ppJob =
+ ThreadPool::getInstance()->enter( pThreadId , (sal_Int64 ) hPool );
rtl_byte_sequence_release( pThreadId );
uno_releaseIdFromCurrentThread();
}
@@ -444,19 +465,19 @@ uno_threadpool_putJob(
void ( SAL_CALL * doRequest ) ( void *pThreadSpecificData ),
sal_Bool bIsOneway ) SAL_THROW_EXTERN_C()
{
- g_threadPool->addJob( pThreadId, bIsOneway, pJob ,doRequest );
+ ThreadPool::getInstance()->addJob( pThreadId, bIsOneway, pJob ,doRequest );
}
extern "C" void SAL_CALL
uno_threadpool_dispose( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C()
{
- g_threadPool->dispose( (sal_Int64 ) hPool );
+ ThreadPool::getInstance()->dispose( (sal_Int64 ) hPool );
}
extern "C" void SAL_CALL
uno_threadpool_destroy( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C()
{
- g_threadPool->stopDisposing( (sal_Int64) hPool );
+ ThreadPool::getInstance()->stopDisposing( (sal_Int64) hPool );
if( hPool )
{
@@ -476,6 +497,4 @@ uno_threadpool_destroy( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C()
g_pThreadpoolHashSet = 0;
}
}
-
- g_threadPool->release();
}