1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <cppu/cppudllapi.h>
30 #include <rtl/byteseq.h>
37 * Thread identifier administration.
40 Establishs an association between the current thread and the given thread identifier.
41 There can be only one association at a time. The association must be broken by
42 uno_releaseIdFromCurrentThread().
43 This method is in general called by a bridge, that wants to bind a remote threadId
46 @param pThreadId a byte sequence, that contains the identifier of the current thread.
47 @return true, when the identifier was registered.
48 false, when the thread has already an identifier. The identifier was not
49 altered. ( This is in general a bug ).
51 @see uno_releaseIdFromCurrentThread()
53 CPPU_DLLPUBLIC sal_Bool SAL_CALL
uno_bindIdToCurrentThread( sal_Sequence
*pThreadId
)
58 Get the identifier of the current thread.
59 If no id has been bound for the thread before, a new one is generated and bound
61 For each call to uno_getIdOfCurrentThread(), a call to uno_releaseIdFromCurrentThread()
64 @param ppThreadId [out] Contains the (acquired) ThreadId.
65 @see uno_releaseIdFromCurrentThread()
67 CPPU_DLLPUBLIC
void SAL_CALL
uno_getIdOfCurrentThread( sal_Sequence
**ppThreadId
)
72 If the internal refcount drops to zero, the association betwen threadId and
75 CPPU_DLLPUBLIC
void SAL_CALL
uno_releaseIdFromCurrentThread()
79 struct _uno_ThreadPool
;
80 typedef struct _uno_ThreadPool
* uno_ThreadPool
;
83 Creates a threadpool handle. Typically each remote bridge instances creates one
86 CPPU_DLLPUBLIC uno_ThreadPool SAL_CALL
87 uno_threadpool_create() SAL_THROW_EXTERN_C();
91 Makes the current thread known to the threadpool. This function must be
92 called, BEFORE uno_threadpool_enter() is called and BEFORE a job for this
93 thread is put into the threadpool (avoid a race between this thread and
94 an incoming request/reply).
95 For every call to uno_threadpool_attach, a corrosponding call to
96 uno_threadpool_detach must be done.
98 @param hPool The bridge threadpool handle previously created by uno_threadpool_create.
101 CPPU_DLLPUBLIC
void SAL_CALL
102 uno_threadpool_attach( uno_ThreadPool hPool
) SAL_THROW_EXTERN_C();
105 This method is called to wait for a reply of a previously sent request. This is a
106 blocking method. uno_threadpool_attach() must have been called before.
108 @param hPool the handle that was previously created by uno_threadpool_create().
109 @param ppJob [out] the pointer, that was given by uno_threadpool_putJob
110 0, when uno_threadpool_dispose() was the reason to fall off from threadpool.
111 @see uno_threadpool_dispose()
113 CPPU_DLLPUBLIC
void SAL_CALL
114 uno_threadpool_enter( uno_ThreadPool hPool
, void **ppJob
)
115 SAL_THROW_EXTERN_C();
118 Detaches the current thread from the threadpool. Must be called for
119 every call to uno_threadpool_attach.
121 CPPU_DLLPUBLIC
void SAL_CALL
122 uno_threadpool_detach( uno_ThreadPool hPool
) SAL_THROW_EXTERN_C();
125 Puts a job into the pool. A job may eiter be a request or a reply
126 (replies have a 0 in the doRequest parameter). This function is non-blocking.
128 A request may either be synchronous or asynchronous.
129 If the request is synchronous, it is first looked up,
130 if there exists a handle with the given
131 identifier. If this is the case, the thread is woken up and the doRequest
132 function is called with the given pJob. If no handle exists,
133 a new thread is created and the given threadId is bound to the new thread.
135 If the request is asynchronous, it is put into the queue of asynchronous
136 requests for the current threadid. The requests are always executed in a new
137 thread, even if the thread with the given id is waiting in the pool. No id is bound
138 to the newly created thread. The responsibilty is left to the bridge ( if it
139 wishes to bind a name).
141 If pJob is a reply, there MUST be a thread with the given threadId waiting
144 @param pThreadId The Id of the thread, that initialized this request. (In general a
146 @param pJob The argument, that doRequest will get or that will be returned by
147 uno_threadpool_enter().
148 @param doRequest The function, that shall be called to execute the request.
149 0 if pJob is a reply.
150 @param bIsOneway True, if the request is asynchrons. False, if it is synchronous.
151 Set to sal_False, if pJob is a reply.
153 CPPU_DLLPUBLIC
void SAL_CALL
154 uno_threadpool_putJob(
155 uno_ThreadPool hPool
,
156 sal_Sequence
*pThreadId
,
158 void ( SAL_CALL
* doRequest
) ( void *pThreadSpecificData
),
159 sal_Bool bIsOneway
) SAL_THROW_EXTERN_C();
162 All threads, that are waiting on the hPool handle, are forced out of the pool.
163 The threads waiting with uno_threadpool_enter() will return with *ppJob == 0
165 Later calls to uno_threadpool_enter() using the hPool handle will also
166 return immeadiatly with *ppJob == 0.
168 @param hPool The handle to be disposed.
170 This function is called i.e. by a bridge, that is forced to dispose itself.
172 CPPU_DLLPUBLIC
void SAL_CALL
173 uno_threadpool_dispose( uno_ThreadPool hPool
) SAL_THROW_EXTERN_C();
176 /** Releases the previously with uno_threadpool_create() created handle.
177 The handle thus becomes invalid. It is an error to use the handle after
178 uno_threadpool_destroy().
180 A call to uno_threadpool_destroy can synchronously join on spawned worker
181 threads, so this function must never be called from such a worker thread.
183 @see uno_threadpool_create()
185 CPPU_DLLPUBLIC
void SAL_CALL
186 uno_threadpool_destroy( uno_ThreadPool hPool
) SAL_THROW_EXTERN_C();
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */