diff options
author | Jörg Budischewski <jbu@openoffice.org> | 2001-02-20 11:43:51 +0000 |
---|---|---|
committer | Jörg Budischewski <jbu@openoffice.org> | 2001-02-20 11:43:51 +0000 |
commit | c4b2ed0d5b5690d2752adf3fff42776603e5e0ca (patch) | |
tree | 1deea143a8701185383cab64b6d9d6948059b27f /cppu | |
parent | 4dcd74de67160e16a5ebc796157ea2789f474504 (diff) |
#83737# uno_threadpool_disposeThreads now offers a feature to join on all previously created threads (when the method is called with a 0 as bridgeID)
Diffstat (limited to 'cppu')
-rw-r--r-- | cppu/source/threadpool/thread.cxx | 84 | ||||
-rw-r--r-- | cppu/source/threadpool/thread.hxx | 23 |
2 files changed, 101 insertions, 6 deletions
diff --git a/cppu/source/threadpool/thread.cxx b/cppu/source/threadpool/thread.cxx index 3ff7d10b3973..d85232335fb1 100644 --- a/cppu/source/threadpool/thread.cxx +++ b/cppu/source/threadpool/thread.cxx @@ -2,9 +2,9 @@ * * $RCSfile: thread.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: jbu $ $Date: 2000-09-29 12:42:17 $ + * last change: $Author: jbu $ $Date: 2001-02-20 12:43:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -67,6 +67,7 @@ #include "threadpool.hxx" +using namespace osl; extern "C" { void SAL_CALL cppu_requestThreadWorker( void *pVoid ) @@ -78,8 +79,73 @@ void SAL_CALL cppu_requestThreadWorker( void *pVoid ) } } + namespace cppu_threadpool { +// ---------------------------------------------------------------------------------- + ThreadAdmin::~ThreadAdmin() + { +#ifdef DEBUG + if( m_lst.size() ) + { + fprintf( stderr, "%d Threads left\n" , m_lst.size() ); + } +#endif + } + + void ThreadAdmin::add( ORequestThread *p ) + { + MutexGuard aGuard( m_mutex ); + m_lst.push_back( p ); + } + + void ThreadAdmin::remove( ORequestThread * p ) + { + MutexGuard aGuard( m_mutex ); + ::std::list< ORequestThread * >::iterator ii = ::std::find( m_lst.begin(), m_lst.end(), p ); + OSL_ASSERT( ii != m_lst.end() ); + m_lst.erase( ii ); + } + + void ThreadAdmin::join() + { + ORequestThread *pCurrent; + do + { + pCurrent = 0; + { + MutexGuard aGuard( m_mutex ); + if( ! m_lst.empty() ) + { + pCurrent = m_lst.front(); + pCurrent->setDeleteSelf( sal_False ); + } + } + if ( pCurrent ) + { + pCurrent->join(); + delete pCurrent; + } + } while( pCurrent ); + } + + ThreadAdmin* ThreadAdmin::getInstance() + { + static ThreadAdmin *pThreadAdmin = 0; + if( ! pThreadAdmin ) + { + MutexGuard guard( Mutex::getGlobalMutex() ); + if( ! pThreadAdmin ) + { + static ThreadAdmin admin; + pThreadAdmin = &admin; + } + } + return pThreadAdmin; + + } + +// ---------------------------------------------------------------------------------- ORequestThread::ORequestThread( JobQueue *pQueue, const ByteSequence &aThreadId, sal_Bool bAsynchron ) @@ -87,8 +153,9 @@ namespace cppu_threadpool { , m_thread( 0 ) , m_aThreadId( aThreadId ) , m_bAsynchron( bAsynchron ) + , m_bDeleteSelf( sal_True ) { - + ThreadAdmin::getInstance()->add( this ); } @@ -122,9 +189,18 @@ namespace cppu_threadpool { return m_thread != 0; } + void ORequestThread::join() + { + osl_joinWithThread( m_thread ); + } + void ORequestThread::onTerminated() { - delete this; + ThreadAdmin::getInstance()->remove( this ); + if( m_bDeleteSelf ) + { + delete this; + } } void ORequestThread::run() diff --git a/cppu/source/threadpool/thread.hxx b/cppu/source/threadpool/thread.hxx index 0099150b71ee..52bf17514ee3 100644 --- a/cppu/source/threadpool/thread.hxx +++ b/cppu/source/threadpool/thread.hxx @@ -2,9 +2,9 @@ * * $RCSfile: thread.hxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: hr $ $Date: 2000-09-18 15:25:52 $ + * last change: $Author: jbu $ $Date: 2001-02-20 12:43:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -61,6 +61,7 @@ #ifndef _CPPU_THREADPOOL_THREAD_HXX #define _CPPU_THREADPOOL_THREAD_HXX +#include <list> #include <osl/types.h> #include <osl/thread.h> @@ -85,14 +86,32 @@ namespace cppu_threadpool { void setTask( JobQueue * , const ::rtl::ByteSequence & aThreadId , sal_Bool bAsynchron ); sal_Bool create(); + void join(); void onTerminated(); void run(); + inline void setDeleteSelf( sal_Bool b ) + { m_bDeleteSelf = b; } private: oslThread m_thread; JobQueue *m_pQueue; ::rtl::ByteSequence m_aThreadId; sal_Bool m_bAsynchron; + sal_Bool m_bDeleteSelf; + }; + + class ThreadAdmin + { + public: + ~ThreadAdmin (); + static ThreadAdmin *getInstance(); + void add( ORequestThread * ); + void remove( ORequestThread * ); + void join(); + + private: + ::osl::Mutex m_mutex; + ::std::list< ORequestThread * > m_lst; }; } // end cppu_threadpool |