diff options
Diffstat (limited to 'cppu')
-rw-r--r-- | cppu/inc/uno/threadpool.h | 213 | ||||
-rw-r--r-- | cppu/source/threadpool/threadpool.cxx | 94 | ||||
-rwxr-xr-x | cppu/util/cppu.map | 13 |
3 files changed, 153 insertions, 167 deletions
diff --git a/cppu/inc/uno/threadpool.h b/cppu/inc/uno/threadpool.h index 82431a4d376a..ca7db2322829 100644 --- a/cppu/inc/uno/threadpool.h +++ b/cppu/inc/uno/threadpool.h @@ -2,9 +2,9 @@ * * $RCSfile: threadpool.h,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: dbo $ $Date: 2001-03-28 10:46:06 $ + * last change: $Author: jbu $ $Date: 2001-05-08 15:55:09 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -70,141 +70,146 @@ extern "C" { * Thread identifier administration. ***/ /** - * Establishs an association between the current thread an the given thread identifier. - * There can be only one association at a time. The association must be broken by - * uno_releaseIdFromCurrentThread. - * This method is in general called by a bridge, that wants to bind a remote threadId - * to a new thread. - * - * @param pThreadId a byte sequence, that contains the identifier of the current thread. - * @return true, when the identifier was registered. <br> - * false, when the thread has already an identifier. The identifier was not - * altered. ( This is in general a bug ). <br> - **/ + Establishs an association between the current thread an the given thread identifier. + There can be only one association at a time. The association must be broken by + uno_releaseIdFromCurrentThread. + This method is in general called by a bridge, that wants to bind a remote threadId + to a new thread. + + @param pThreadId a byte sequence, that contains the identifier of the current thread. + @return true, when the identifier was registered. <br> + false, when the thread has already an identifier. The identifier was not + altered. ( This is in general a bug ). <br> + */ sal_Bool SAL_CALL uno_bindIdToCurrentThread( sal_Sequence *pThreadId ) SAL_THROW_EXTERN_C(); /** - * Get the identifier of the current thread. - * If no id has been bound for the thread before, a new one is generated and bound - * to the thread. - * For each call to uno_getIdOfCurrentThread, a call to uno_releaseIdFromCurrentThread - * must be done. - * - * @param ppThreadId [out] Contains the (acquired) ThreadId. - **/ + Get the identifier of the current thread. + If no id has been bound for the thread before, a new one is generated and bound + to the thread. + For each call to uno_getIdOfCurrentThread, a call to uno_releaseIdFromCurrentThread + must be done. + + @param ppThreadId [out] Contains the (acquired) ThreadId. + */ void SAL_CALL uno_getIdOfCurrentThread( sal_Sequence **ppThreadId ) SAL_THROW_EXTERN_C(); /** - * If the internal refcount drops to zero, the association betwen threadId and - * thread is broken. - **/ + If the internal refcount drops to zero, the association betwen threadId and + thread is broken. + */ void SAL_CALL uno_releaseIdFromCurrentThread() SAL_THROW_EXTERN_C(); +struct _uno_ThreadPool; +typedef struct _uno_ThreadPool * uno_ThreadPool; + /** - * The threadpool - **/ -struct uno_threadpool_Handle; + Creates a threadpool handle. Typically each remote bridge instances creates one + handle. + */ +uno_ThreadPool SAL_CALL +uno_threadpool_create() SAL_THROW_EXTERN_C(); + + /** - * Create a handle for the current thread before entering waiting pool. This method must be - * called, BEFORE the request is sent (to avoid a race between this thread and an incoming - * reply). - * This method shall only be called for synchronous requests. - * - * @param nDisposeId An ID, that uniquely identifies a bridge within the - * local process. The pointer to the bridge object should be used. - * @see uno_threadpool_disposeThreads - ***/ -struct uno_threadpool_Handle * SAL_CALL -uno_threadpool_createHandle( sal_Int64 nDisposeId ) SAL_THROW_EXTERN_C(); + Makes the current thread known to the threadpool. This function must be + called, BEFORE uno_threadpool_enter() is called and BEFORE a job for this + thread is put into the threadpool (avoid a race between this thread and + an incoming request/reply). + For every call to uno_threadpool_attach, a corrosponding call to + uno_threadpool_detach must be done. + + @param hPool The bridge threadpool handle previously created by uno_threadpool_create. + +*/ +void SAL_CALL +uno_threadpool_attach( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); /** - * This method is called to wait for a reply of a previously sent request. This is a - * blocking method. - * - * @param pHandle the handle that was previously created by uno_threadpool_createHandle. - * @param ppThreadSpecificData [out] the pointer, that was given by uno_threadpool_reply. - * If the threads for this bridge were disposed, - * *ppThreadSpecificData is null. + This method is called to wait for a reply of a previously sent request. This is a + blocking method. uno_threadpool_attach() must have been called before. + + @param hPool the handle that was previously created by uno_threadpool_create(). + @param ppJob [out] the pointer, that was given by uno_threadpool_putJob + 0, when uno_threadpool_dispose was the reason to fall off from threadpool. **/ void SAL_CALL -uno_threadpool_enter( struct uno_threadpool_Handle * pHandle , void **ppThreadSpecificData ) +uno_threadpool_enter( uno_ThreadPool hPool , void **ppJob ) SAL_THROW_EXTERN_C(); - /** - * A request is put into a queue of waiting requests. This method is non-blocking. - * - * If the request is synchronous, it is first looked up, - * if there exists a handle with the given - * identifier. If this is the case, the thread is woken up and the doRequest - * function is called with the given pThreadSpecificData. If no handle exists, - * a new thread is created and the given threadId is bound to the new thread. - * - * If the request is asynchronous, it is put into the queue of asynchronous - * requests for the current threadid. The requests are always executed in a new - * thread, even if the thread with the given Id waiting in the pool. No Id is bound - * to the newly created thread. The responsibilty is left to the bridge ( if it - * wishes to bind a name). - * - * @param pThreadId The Id of thread, that initialized this request. (In general a - * remote threadid). - * @param pThreadSpecificData The argument, that doRequest will get. - * @param doRequest The function, that shall be called to execute the request. - * @param bIsOneway True, if the request is asynchrons. False, if it is synchronous - * - **/ + Detaches the current thread from the threadpool. Must be called for + every call to uno_threadpool_attach. +*/ void SAL_CALL -uno_threadpool_putRequest( sal_Sequence *pThreadId, - void *pThreadSpecificData, - void ( SAL_CALL * doRequest ) ( void *pThreadSpecificData ), - sal_Bool bIsOneway ) SAL_THROW_EXTERN_C(); - +uno_threadpool_detach( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); /** - * A reply is put into the threadpool. There MUST be a thread with the given threadId waiting - * for this reply. This method is non-blocking. - * - * @param pThreadSpecificData The pointer, that is returned by uno_threadpool_enter. - **/ + Puts a job into the pool. A job may eiter be a request or a reply + (replies have a 0 in the doRequest parameter). This function is non-blocking. + + A request may either be synchronous or asynchronous. + If the request is synchronous, it is first looked up, + if there exists a handle with the given + identifier. If this is the case, the thread is woken up and the doRequest + function is called with the given pJob. If no handle exists, + a new thread is created and the given threadId is bound to the new thread. + + If the request is asynchronous, it is put into the queue of asynchronous + requests for the current threadid. The requests are always executed in a new + thread, even if the thread with the given id is waiting in the pool. No id is bound + to the newly created thread. The responsibilty is left to the bridge ( if it + wishes to bind a name). + + If pJob is a reply, there MUST be a thread with the given threadId waiting + for this reply. + + @param pThreadId The Id of the thread, that initialized this request. (In general a + remote threadid). + @param pJob The argument, that doRequest will get or that will be returned by + uno_threadpool_enter(). + @param doRequest The function, that shall be called to execute the request. + 0 if pJob is a reply. + @param bIsOneway True, if the request is asynchrons. False, if it is synchronous. + Set to sal_False, if pJob is a reply. + */ void SAL_CALL -uno_threadpool_putReply( sal_Sequence *pThreadId, void *pThreadSpecificData ) SAL_THROW_EXTERN_C(); - +uno_threadpool_putJob( + uno_ThreadPool hPool, + sal_Sequence *pThreadId, + void *pJob, + void ( SAL_CALL * doRequest ) ( void *pThreadSpecificData ), + sal_Bool bIsOneway ) SAL_THROW_EXTERN_C(); /** - * All threads, that are waiting on handles, that were created with - * nDisposeId, are forced out of the pool. - * (@see uno_threadpool_createTicket) These threads will return from - * uno_threadpool_enter with 0 == *ppThreadSpecificData. - * Later calls to uno_threadpool_enter with the given disposeId also - * return immeadiatly. - * - * @param nDisposeId Identfies the caller of uno_threadpool_createTicket - * - * This function is called i.e. by a bridge, that is forced to dispose itself. - * When disposing of the bridge has finished, the bridge MUST call - * uno_threadpool_stopDisposeThreads. - **/ + All threads, that are waiting on the hPool handle, are forced out of the pool. + The threads waiting with uno_threadpool_enter() will return with *ppJob == 0 + + Later calls to uno_threadpool_enter() using the hPool handle will also + return immeadiatly with *ppJob == 0. + + @param hPool The handle to be disposed. + In case, hPool is 0, this function joins on all threads created + by the threadpool administration. + + This function is called i.e. by a bridge, that is forced to dispose itself. + */ void SAL_CALL -uno_threadpool_disposeThreads( sal_Int64 nDisposeId ) SAL_THROW_EXTERN_C(); +uno_threadpool_dispose( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); -/** - * Informs the threadpool, that no special treatment is needed for the given nDisposeId. - * This allows the threadpool to release internal resources - * and must be called after all threads originated from this bridge have returned. - * (This can in general be done in the bridge destructor). - * - * @param nDisposeId Identifies the caller of uno_threadpool_createTicket - * @see uno_threadpool_disposeThreads - **/ +/** Releases the previously with uno_threadpool_create() created handle. + The handle thus becomes invalid. It is an error to use the handle after + uno_threadpool_destroy(). + */ void SAL_CALL -uno_threadpool_stopDisposeThreads( sal_Int64 nDisposeId ) SAL_THROW_EXTERN_C(); +uno_threadpool_destroy( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); #ifdef __cplusplus } diff --git a/cppu/source/threadpool/threadpool.cxx b/cppu/source/threadpool/threadpool.cxx index 19ef12c22e35..bd34884c3ff0 100644 --- a/cppu/source/threadpool/threadpool.cxx +++ b/cppu/source/threadpool/threadpool.cxx @@ -2,9 +2,9 @@ * * $RCSfile: threadpool.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: dbo $ $Date: 2001-03-28 10:46:08 $ + * last change: $Author: jbu $ $Date: 2001-05-08 15:55:45 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -73,20 +73,6 @@ using namespace ::std; using namespace ::osl; -struct uno_threadpool_Handle -{ - /** - * Global Threadidentifier of the waiting thread - **/ - uno_threadpool_Handle( const ByteSequence &aThreadId_ , sal_Int64 nDisposeId_ ) - : aThreadId( aThreadId_ ) - , nDisposeId( nDisposeId_ ) - {} - - ByteSequence aThreadId; - sal_Int64 nDisposeId; -}; - namespace cppu_threadpool { DisposedCallerAdmin *DisposedCallerAdmin::getInstance() @@ -428,69 +414,63 @@ namespace cppu_threadpool using namespace cppu_threadpool; +static oslInterlockedCount g_hPool; -//------------------------------ -// -// The C-Interface -// -//------------------------------- -extern "C" void SAL_CALL uno_threadpool_putRequest( - sal_Sequence *pThreadId, void *pThreadSpecificData, - void ( SAL_CALL * doRequest ) ( void *pThreadSpecificData ), sal_Bool bIsOneway ) - SAL_THROW_EXTERN_C() +extern "C" uno_ThreadPool SAL_CALL +uno_threadpool_create() SAL_THROW_EXTERN_C() { - ThreadPool::getInstance()->addJob( pThreadId, bIsOneway, pThreadSpecificData,doRequest ); + // Just ensure that the number is unique in this process + uno_ThreadPool h = ( uno_ThreadPool ) osl_incrementInterlockedCount( &g_hPool ); + return h; } - - -extern "C" void SAL_CALL uno_threadpool_putReply( - sal_Sequence *pThreadId, void *pThreadSpecificData ) - SAL_THROW_EXTERN_C() +extern "C" void SAL_CALL +uno_threadpool_attach( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C() { - ThreadPool::getInstance()->addJob( pThreadId, sal_False, pThreadSpecificData, 0 ); + sal_Sequence *pThreadId = 0; + uno_getIdOfCurrentThread( &pThreadId ); + ThreadPool::getInstance()->prepare( pThreadId ); + rtl_byte_sequence_release( pThreadId ); + uno_releaseIdFromCurrentThread(); } - -extern "C" struct uno_threadpool_Handle * SAL_CALL -uno_threadpool_createHandle( sal_Int64 nDisposeId ) +extern "C" void SAL_CALL +uno_threadpool_enter( uno_ThreadPool hPool , void **ppJob ) SAL_THROW_EXTERN_C() { sal_Sequence *pThreadId = 0; uno_getIdOfCurrentThread( &pThreadId ); - - struct uno_threadpool_Handle *pHandle = new uno_threadpool_Handle( pThreadId, nDisposeId ); - ThreadPool::getInstance()->prepare( pThreadId ); - + *ppJob = + ThreadPool::getInstance()->enter( pThreadId , (sal_Int64 ) hPool ); rtl_byte_sequence_release( pThreadId ); - - return pHandle; + uno_releaseIdFromCurrentThread(); } -extern "C" void SAL_CALL uno_threadpool_enter( - struct uno_threadpool_Handle *pHandle , void **ppThreadSpecificData ) - SAL_THROW_EXTERN_C() +extern "C" void SAL_CALL +uno_threadpool_detach( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C() { - OSL_ASSERT( ppThreadSpecificData ); - - *ppThreadSpecificData = - ThreadPool::getInstance()->enter( pHandle->aThreadId , pHandle->nDisposeId ); - - uno_releaseIdFromCurrentThread(); - delete pHandle; + // we might do here some tiding up in case a thread called attach but never detach } +extern "C" void SAL_CALL +uno_threadpool_putJob( + uno_ThreadPool hPool, + sal_Sequence *pThreadId, + void *pJob, + void ( SAL_CALL * doRequest ) ( void *pThreadSpecificData ), + sal_Bool bIsOneway ) SAL_THROW_EXTERN_C() +{ + ThreadPool::getInstance()->addJob( pThreadId, bIsOneway, pJob ,doRequest ); +} extern "C" void SAL_CALL -uno_threadpool_disposeThreads( sal_Int64 nDisposeId ) - SAL_THROW_EXTERN_C() +uno_threadpool_dispose( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C() { - ThreadPool::getInstance()->dispose( nDisposeId ); + ThreadPool::getInstance()->dispose( (sal_Int64 ) hPool ); } extern "C" void SAL_CALL -uno_threadpool_stopDisposeThreads( sal_Int64 nDisposeId ) - SAL_THROW_EXTERN_C() +uno_threadpool_destroy( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C() { - ThreadPool::getInstance()->stopDisposing( nDisposeId ); + ThreadPool::getInstance()->stopDisposing( (sal_Int64) hPool ); } diff --git a/cppu/util/cppu.map b/cppu/util/cppu.map index 802c18941bbb..68a284538337 100755 --- a/cppu/util/cppu.map +++ b/cppu/util/cppu.map @@ -83,12 +83,13 @@ UDK_2_0_0 { uno_bindIdToCurrentThread; uno_getIdOfCurrentThread; uno_releaseIdFromCurrentThread; - uno_threadpool_enter; - uno_threadpool_createHandle; - uno_threadpool_putRequest; - uno_threadpool_putReply; - uno_threadpool_disposeThreads; - uno_threadpool_stopDisposeThreads; + uno_threadpool_enter + uno_threadpool_create + uno_threadpool_destroy + uno_threadpool_putJob + uno_threadpool_dispose + uno_threadpool_attach + uno_threadpool_detach local: *; }; |