1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include <sal/types.h> 29*cdf0e10cSrcweir #include <rtl/byteseq.h> 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #ifdef __cplusplus 32*cdf0e10cSrcweir extern "C" { 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir /*** 36*cdf0e10cSrcweir * Thread identifier administration. 37*cdf0e10cSrcweir ***/ 38*cdf0e10cSrcweir /** 39*cdf0e10cSrcweir Establishs an association between the current thread and the given thread identifier. 40*cdf0e10cSrcweir There can be only one association at a time. The association must be broken by 41*cdf0e10cSrcweir uno_releaseIdFromCurrentThread(). 42*cdf0e10cSrcweir This method is in general called by a bridge, that wants to bind a remote threadId 43*cdf0e10cSrcweir to a new thread. 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir @param pThreadId a byte sequence, that contains the identifier of the current thread. 46*cdf0e10cSrcweir @return true, when the identifier was registered. 47*cdf0e10cSrcweir false, when the thread has already an identifier. The identifier was not 48*cdf0e10cSrcweir altered. ( This is in general a bug ). 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir @see uno_releaseIdFromCurrentThread() 51*cdf0e10cSrcweir */ 52*cdf0e10cSrcweir sal_Bool SAL_CALL uno_bindIdToCurrentThread( sal_Sequence *pThreadId ) 53*cdf0e10cSrcweir SAL_THROW_EXTERN_C(); 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir /** 57*cdf0e10cSrcweir Get the identifier of the current thread. 58*cdf0e10cSrcweir If no id has been bound for the thread before, a new one is generated and bound 59*cdf0e10cSrcweir to the thread. 60*cdf0e10cSrcweir For each call to uno_getIdOfCurrentThread(), a call to uno_releaseIdFromCurrentThread() 61*cdf0e10cSrcweir must be done. 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir @param ppThreadId [out] Contains the (acquired) ThreadId. 64*cdf0e10cSrcweir @see uno_releaseIdFromCurrentThread() 65*cdf0e10cSrcweir */ 66*cdf0e10cSrcweir void SAL_CALL uno_getIdOfCurrentThread( sal_Sequence **ppThreadId ) 67*cdf0e10cSrcweir SAL_THROW_EXTERN_C(); 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir /** 71*cdf0e10cSrcweir If the internal refcount drops to zero, the association betwen threadId and 72*cdf0e10cSrcweir thread is broken. 73*cdf0e10cSrcweir */ 74*cdf0e10cSrcweir void SAL_CALL uno_releaseIdFromCurrentThread() 75*cdf0e10cSrcweir SAL_THROW_EXTERN_C(); 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir struct _uno_ThreadPool; 79*cdf0e10cSrcweir typedef struct _uno_ThreadPool * uno_ThreadPool; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir /** 82*cdf0e10cSrcweir Creates a threadpool handle. Typically each remote bridge instances creates one 83*cdf0e10cSrcweir handle. 84*cdf0e10cSrcweir */ 85*cdf0e10cSrcweir uno_ThreadPool SAL_CALL 86*cdf0e10cSrcweir uno_threadpool_create() SAL_THROW_EXTERN_C(); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir /** 90*cdf0e10cSrcweir Makes the current thread known to the threadpool. This function must be 91*cdf0e10cSrcweir called, BEFORE uno_threadpool_enter() is called and BEFORE a job for this 92*cdf0e10cSrcweir thread is put into the threadpool (avoid a race between this thread and 93*cdf0e10cSrcweir an incoming request/reply). 94*cdf0e10cSrcweir For every call to uno_threadpool_attach, a corrosponding call to 95*cdf0e10cSrcweir uno_threadpool_detach must be done. 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir @param hPool The bridge threadpool handle previously created by uno_threadpool_create. 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir */ 100*cdf0e10cSrcweir void SAL_CALL 101*cdf0e10cSrcweir uno_threadpool_attach( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir /** 104*cdf0e10cSrcweir This method is called to wait for a reply of a previously sent request. This is a 105*cdf0e10cSrcweir blocking method. uno_threadpool_attach() must have been called before. 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir @param hPool the handle that was previously created by uno_threadpool_create(). 108*cdf0e10cSrcweir @param ppJob [out] the pointer, that was given by uno_threadpool_putJob 109*cdf0e10cSrcweir 0, when uno_threadpool_dispose() was the reason to fall off from threadpool. 110*cdf0e10cSrcweir @see uno_threadpool_dispose() 111*cdf0e10cSrcweir **/ 112*cdf0e10cSrcweir void SAL_CALL 113*cdf0e10cSrcweir uno_threadpool_enter( uno_ThreadPool hPool , void **ppJob ) 114*cdf0e10cSrcweir SAL_THROW_EXTERN_C(); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir /** 117*cdf0e10cSrcweir Detaches the current thread from the threadpool. Must be called for 118*cdf0e10cSrcweir every call to uno_threadpool_attach. 119*cdf0e10cSrcweir */ 120*cdf0e10cSrcweir void SAL_CALL 121*cdf0e10cSrcweir uno_threadpool_detach( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir /** 124*cdf0e10cSrcweir Puts a job into the pool. A job may eiter be a request or a reply 125*cdf0e10cSrcweir (replies have a 0 in the doRequest parameter). This function is non-blocking. 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir A request may either be synchronous or asynchronous. 128*cdf0e10cSrcweir If the request is synchronous, it is first looked up, 129*cdf0e10cSrcweir if there exists a handle with the given 130*cdf0e10cSrcweir identifier. If this is the case, the thread is woken up and the doRequest 131*cdf0e10cSrcweir function is called with the given pJob. If no handle exists, 132*cdf0e10cSrcweir a new thread is created and the given threadId is bound to the new thread. 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir If the request is asynchronous, it is put into the queue of asynchronous 135*cdf0e10cSrcweir requests for the current threadid. The requests are always executed in a new 136*cdf0e10cSrcweir thread, even if the thread with the given id is waiting in the pool. No id is bound 137*cdf0e10cSrcweir to the newly created thread. The responsibilty is left to the bridge ( if it 138*cdf0e10cSrcweir wishes to bind a name). 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir If pJob is a reply, there MUST be a thread with the given threadId waiting 141*cdf0e10cSrcweir for this reply. 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir @param pThreadId The Id of the thread, that initialized this request. (In general a 144*cdf0e10cSrcweir remote threadid). 145*cdf0e10cSrcweir @param pJob The argument, that doRequest will get or that will be returned by 146*cdf0e10cSrcweir uno_threadpool_enter(). 147*cdf0e10cSrcweir @param doRequest The function, that shall be called to execute the request. 148*cdf0e10cSrcweir 0 if pJob is a reply. 149*cdf0e10cSrcweir @param bIsOneway True, if the request is asynchrons. False, if it is synchronous. 150*cdf0e10cSrcweir Set to sal_False, if pJob is a reply. 151*cdf0e10cSrcweir */ 152*cdf0e10cSrcweir void SAL_CALL 153*cdf0e10cSrcweir uno_threadpool_putJob( 154*cdf0e10cSrcweir uno_ThreadPool hPool, 155*cdf0e10cSrcweir sal_Sequence *pThreadId, 156*cdf0e10cSrcweir void *pJob, 157*cdf0e10cSrcweir void ( SAL_CALL * doRequest ) ( void *pThreadSpecificData ), 158*cdf0e10cSrcweir sal_Bool bIsOneway ) SAL_THROW_EXTERN_C(); 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir /** 161*cdf0e10cSrcweir All threads, that are waiting on the hPool handle, are forced out of the pool. 162*cdf0e10cSrcweir The threads waiting with uno_threadpool_enter() will return with *ppJob == 0 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir Later calls to uno_threadpool_enter() using the hPool handle will also 165*cdf0e10cSrcweir return immeadiatly with *ppJob == 0. 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir @param hPool The handle to be disposed. 168*cdf0e10cSrcweir In case, hPool is 0, this function joins on all threads created 169*cdf0e10cSrcweir by the threadpool administration. This may e.g. used to ensure, that 170*cdf0e10cSrcweir no threads are inside the cppu library anymore, in case it needs to get 171*cdf0e10cSrcweir unloaded. 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir This function is called i.e. by a bridge, that is forced to dispose itself. 174*cdf0e10cSrcweir */ 175*cdf0e10cSrcweir void SAL_CALL 176*cdf0e10cSrcweir uno_threadpool_dispose( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir /** Releases the previously with uno_threadpool_create() created handle. 180*cdf0e10cSrcweir The handle thus becomes invalid. It is an error to use the handle after 181*cdf0e10cSrcweir uno_threadpool_destroy(). 182*cdf0e10cSrcweir @see uno_threadpool_create() 183*cdf0e10cSrcweir */ 184*cdf0e10cSrcweir void SAL_CALL 185*cdf0e10cSrcweir uno_threadpool_destroy( uno_ThreadPool hPool ) SAL_THROW_EXTERN_C(); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir #ifdef __cplusplus 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir #endif 190