1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is the Netscape Portable Runtime (NSPR).
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998-2000
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | #ifndef pprthred_h___
|
---|
39 | #define pprthred_h___
|
---|
40 |
|
---|
41 | /*
|
---|
42 | ** API for PR private functions. These calls are to be used by internal
|
---|
43 | ** developers only.
|
---|
44 | */
|
---|
45 | #include "nspr.h"
|
---|
46 |
|
---|
47 | #if defined(XP_OS2)
|
---|
48 | #define INCL_DOS
|
---|
49 | #define INCL_DOSERRORS
|
---|
50 | #define INCL_WIN
|
---|
51 | #include <os2.h>
|
---|
52 | #endif
|
---|
53 |
|
---|
54 | #ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
|
---|
55 | #define PR_AttachThread VBoxNsprPR_AttachThread
|
---|
56 | #define PR_DetachThread VBoxNsprPR_DetachThread
|
---|
57 | #define PR_GetThreadID VBoxNsprPR_GetThreadID
|
---|
58 | #define PR_SetThreadDumpProc VBoxNsprPR_SetThreadDumpProc
|
---|
59 | #define PR_GetThreadAffinityMask VBoxNsprPR_GetThreadAffinityMask
|
---|
60 | #define PR_SetThreadAffinityMask VBoxNsprPR_SetThreadAffinityMask
|
---|
61 | #define PR_SetCPUAffinityMask VBoxNsprPR_SetCPUAffinityMask
|
---|
62 | #define PR_ShowStatus VBoxNsprPR_ShowStatus
|
---|
63 | #define PR_SetThreadRecycleMode VBoxNsprPR_SetThreadRecycleMode
|
---|
64 | #define PR_CreateThreadGCAble VBoxNsprPR_CreateThreadGCAble
|
---|
65 | #define PR_AttachThreadGCAble VBoxNsprPR_AttachThreadGCAble
|
---|
66 | #define PR_SetThreadGCAble VBoxNsprPR_SetThreadGCAble
|
---|
67 | #define PR_ClearThreadGCAble VBoxNsprPR_ClearThreadGCAble
|
---|
68 | #define PR_SuspendAll VBoxNsprPR_SuspendAll
|
---|
69 | #define PR_ResumeAll VBoxNsprPR_ResumeAll
|
---|
70 | #define PR_GetSP VBoxNsprPR_GetSP
|
---|
71 | #define PR_GetGCRegisters VBoxNsprPR_GetGCRegisters
|
---|
72 | #define GetExecutionEnvironment VBoxNsprGetExecutionEnvironment
|
---|
73 | #define SetExecutionEnvironment VBoxNsprSetExecutionEnvironment
|
---|
74 | #define PR_EnumerateThreads VBoxNsprPR_EnumerateThreads
|
---|
75 | #define PR_ThreadScanStackPointers VBoxNsprPR_ThreadScanStackPointers
|
---|
76 | #define PR_ScanStackPointers VBoxNsprPR_ScanStackPointers
|
---|
77 | #define PR_GetStackSpaceLeft VBoxNsprPR_GetStackSpaceLeft
|
---|
78 | #define PR_NewNamedMonitor VBoxNsprPR_NewNamedMonitor
|
---|
79 | #define PR_TestAndLock VBoxNsprPR_TestAndLock
|
---|
80 | #define PR_TestAndEnterMonitor VBoxNsprPR_TestAndEnterMonitor
|
---|
81 | #define PR_GetMonitorEntryCount VBoxNsprPR_GetMonitorEntryCount
|
---|
82 | #define PR_CTestAndEnterMonitor VBoxNsprPR_CTestAndEnterMonitor
|
---|
83 | #define PR_Mac_WaitForAsyncNotify VBoxNsprPR_Mac_WaitForAsyncNotify
|
---|
84 | #define PR_Mac_PostAsyncNotify VBoxNsprPR_Mac_PostAsyncNotify
|
---|
85 | #define PR_OS2_SetFloatExcpHandler VBoxNsprPR_OS2_SetFloatExcpHandler
|
---|
86 | #define PR_OS2_UnsetFloatExcpHandler VBoxNsprPR_OS2_UnsetFloatExcpHandler
|
---|
87 | #define PR_XLock VBoxNsprPR_XLock
|
---|
88 | #define PR_XUnlock VBoxNsprPR_XUnlock
|
---|
89 | #define PR_XIsLocked VBoxNsprPR_XIsLocked
|
---|
90 | #define PR_XWait VBoxNsprPR_XWait
|
---|
91 | #define PR_XNotify VBoxNsprPR_XNotify
|
---|
92 | #define PR_XNotifyAll VBoxNsprPR_XNotifyAll
|
---|
93 | #endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
|
---|
94 |
|
---|
95 | PR_BEGIN_EXTERN_C
|
---|
96 |
|
---|
97 | /*---------------------------------------------------------------------------
|
---|
98 | ** THREAD PRIVATE FUNCTIONS
|
---|
99 | ---------------------------------------------------------------------------*/
|
---|
100 |
|
---|
101 | /*
|
---|
102 | ** Associate a thread object with an existing native thread.
|
---|
103 | ** "type" is the type of thread object to attach
|
---|
104 | ** "priority" is the priority to assign to the thread
|
---|
105 | ** "stack" defines the shape of the threads stack
|
---|
106 | **
|
---|
107 | ** This can return NULL if some kind of error occurs, or if memory is
|
---|
108 | ** tight. This call invokes "start(obj,arg)" and returns when the
|
---|
109 | ** function returns. The thread object is automatically destroyed.
|
---|
110 | **
|
---|
111 | ** This call is not normally needed unless you create your own native
|
---|
112 | ** thread. PR_Init does this automatically for the primordial thread.
|
---|
113 | */
|
---|
114 | NSPR_API(PRThread*) PR_AttachThread(PRThreadType type,
|
---|
115 | PRThreadPriority priority,
|
---|
116 | PRThreadStack *stack);
|
---|
117 |
|
---|
118 | /*
|
---|
119 | ** Detach the nspr thread from the currently executing native thread.
|
---|
120 | ** The thread object will be destroyed and all related data attached
|
---|
121 | ** to it. The exit procs will be invoked.
|
---|
122 | **
|
---|
123 | ** This call is not normally needed unless you create your own native
|
---|
124 | ** thread. PR_Exit will automatially detach the nspr thread object
|
---|
125 | ** created by PR_Init for the primordial thread.
|
---|
126 | **
|
---|
127 | ** This call returns after the nspr thread object is destroyed.
|
---|
128 | */
|
---|
129 | NSPR_API(void) PR_DetachThread(void);
|
---|
130 |
|
---|
131 | /*
|
---|
132 | ** Get the id of the named thread. Each thread is assigned a unique id
|
---|
133 | ** when it is created or attached.
|
---|
134 | */
|
---|
135 | NSPR_API(PRUint32) PR_GetThreadID(PRThread *thread);
|
---|
136 |
|
---|
137 | /*
|
---|
138 | ** Set the procedure that is called when a thread is dumped. The procedure
|
---|
139 | ** will be applied to the argument, arg, when called. Setting the procedure
|
---|
140 | ** to NULL effectively removes it.
|
---|
141 | */
|
---|
142 | typedef void (*PRThreadDumpProc)(PRFileDesc *fd, PRThread *t, void *arg);
|
---|
143 | NSPR_API(void) PR_SetThreadDumpProc(
|
---|
144 | PRThread* thread, PRThreadDumpProc dump, void *arg);
|
---|
145 |
|
---|
146 | /*
|
---|
147 | ** Get this thread's affinity mask. The affinity mask is a 32 bit quantity
|
---|
148 | ** marking a bit for each processor this process is allowed to run on.
|
---|
149 | ** The processor mask is returned in the mask argument.
|
---|
150 | ** The least-significant-bit represents processor 0.
|
---|
151 | **
|
---|
152 | ** Returns 0 on success, -1 on failure.
|
---|
153 | */
|
---|
154 | NSPR_API(PRInt32) PR_GetThreadAffinityMask(PRThread *thread, PRUint32 *mask);
|
---|
155 |
|
---|
156 | /*
|
---|
157 | ** Set this thread's affinity mask.
|
---|
158 | **
|
---|
159 | ** Returns 0 on success, -1 on failure.
|
---|
160 | */
|
---|
161 | NSPR_API(PRInt32) PR_SetThreadAffinityMask(PRThread *thread, PRUint32 mask );
|
---|
162 |
|
---|
163 | /*
|
---|
164 | ** Set the default CPU Affinity mask.
|
---|
165 | **
|
---|
166 | */
|
---|
167 | NSPR_API(PRInt32) PR_SetCPUAffinityMask(PRUint32 mask);
|
---|
168 |
|
---|
169 | /*
|
---|
170 | ** Show status of all threads to standard error output.
|
---|
171 | */
|
---|
172 | NSPR_API(void) PR_ShowStatus(void);
|
---|
173 |
|
---|
174 | /*
|
---|
175 | ** Set thread recycle mode to on (1) or off (0)
|
---|
176 | */
|
---|
177 | NSPR_API(void) PR_SetThreadRecycleMode(PRUint32 flag);
|
---|
178 |
|
---|
179 |
|
---|
180 | /*---------------------------------------------------------------------------
|
---|
181 | ** THREAD PRIVATE FUNCTIONS FOR GARBAGE COLLECTIBLE THREADS
|
---|
182 | ---------------------------------------------------------------------------*/
|
---|
183 |
|
---|
184 | /*
|
---|
185 | ** Only Garbage collectible threads participate in resume all, suspend all and
|
---|
186 | ** enumeration operations. They are also different during creation when
|
---|
187 | ** platform specific action may be needed (For example, all Solaris GC able
|
---|
188 | ** threads are bound threads).
|
---|
189 | */
|
---|
190 |
|
---|
191 | /*
|
---|
192 | ** Same as PR_CreateThread except that the thread is marked as garbage
|
---|
193 | ** collectible.
|
---|
194 | */
|
---|
195 | NSPR_API(PRThread*) PR_CreateThreadGCAble(PRThreadType type,
|
---|
196 | void (*start)(void *arg),
|
---|
197 | void *arg,
|
---|
198 | PRThreadPriority priority,
|
---|
199 | PRThreadScope scope,
|
---|
200 | PRThreadState state,
|
---|
201 | PRUint32 stackSize);
|
---|
202 |
|
---|
203 | /*
|
---|
204 | ** Same as PR_AttachThread except that the thread being attached is marked as
|
---|
205 | ** garbage collectible.
|
---|
206 | */
|
---|
207 | NSPR_API(PRThread*) PR_AttachThreadGCAble(PRThreadType type,
|
---|
208 | PRThreadPriority priority,
|
---|
209 | PRThreadStack *stack);
|
---|
210 |
|
---|
211 | /*
|
---|
212 | ** Mark the thread as garbage collectible.
|
---|
213 | */
|
---|
214 | NSPR_API(void) PR_SetThreadGCAble(void);
|
---|
215 |
|
---|
216 | /*
|
---|
217 | ** Unmark the thread as garbage collectible.
|
---|
218 | */
|
---|
219 | NSPR_API(void) PR_ClearThreadGCAble(void);
|
---|
220 |
|
---|
221 | /*
|
---|
222 | ** This routine prevents all other GC able threads from running. This call is needed by
|
---|
223 | ** the garbage collector.
|
---|
224 | */
|
---|
225 | NSPR_API(void) PR_SuspendAll(void);
|
---|
226 |
|
---|
227 | /*
|
---|
228 | ** This routine unblocks all other GC able threads that were suspended from running by
|
---|
229 | ** PR_SuspendAll(). This call is needed by the garbage collector.
|
---|
230 | */
|
---|
231 | NSPR_API(void) PR_ResumeAll(void);
|
---|
232 |
|
---|
233 | /*
|
---|
234 | ** Return the thread stack pointer of the given thread.
|
---|
235 | ** Needed by the garbage collector.
|
---|
236 | */
|
---|
237 | NSPR_API(void *) PR_GetSP(PRThread *thread);
|
---|
238 |
|
---|
239 | /*
|
---|
240 | ** Save the registers that the GC would find interesting into the thread
|
---|
241 | ** "t". isCurrent will be non-zero if the thread state that is being
|
---|
242 | ** saved is the currently executing thread. Return the address of the
|
---|
243 | ** first register to be scanned as well as the number of registers to
|
---|
244 | ** scan in "np".
|
---|
245 | **
|
---|
246 | ** If "isCurrent" is non-zero then it is allowed for the thread context
|
---|
247 | ** area to be used as scratch storage to hold just the registers
|
---|
248 | ** necessary for scanning.
|
---|
249 | **
|
---|
250 | ** This function simply calls the internal function _MD_HomeGCRegisters().
|
---|
251 | */
|
---|
252 | NSPR_API(PRWord *) PR_GetGCRegisters(PRThread *t, int isCurrent, int *np);
|
---|
253 |
|
---|
254 | /*
|
---|
255 | ** (Get|Set)ExecutionEnvironent
|
---|
256 | **
|
---|
257 | ** Used by Java to associate it's execution environment so garbage collector
|
---|
258 | ** can find it. If return is NULL, then it's probably not a collectable thread.
|
---|
259 | **
|
---|
260 | ** There's no locking required around these calls.
|
---|
261 | */
|
---|
262 | NSPR_API(void*) GetExecutionEnvironment(PRThread *thread);
|
---|
263 | NSPR_API(void) SetExecutionEnvironment(PRThread* thread, void *environment);
|
---|
264 |
|
---|
265 | /*
|
---|
266 | ** Enumeration function that applies "func(thread,i,arg)" to each active
|
---|
267 | ** thread in the process. The enumerator returns PR_SUCCESS if the enumeration
|
---|
268 | ** should continue, any other value is considered failure, and enumeration
|
---|
269 | ** stops, returning the failure value from PR_EnumerateThreads.
|
---|
270 | ** Needed by the garbage collector.
|
---|
271 | */
|
---|
272 | typedef PRStatus (PR_CALLBACK *PREnumerator)(PRThread *t, int i, void *arg);
|
---|
273 | NSPR_API(PRStatus) PR_EnumerateThreads(PREnumerator func, void *arg);
|
---|
274 |
|
---|
275 | /*
|
---|
276 | ** Signature of a thread stack scanning function. It is applied to every
|
---|
277 | ** contiguous group of potential pointers within a thread. Count denotes the
|
---|
278 | ** number of pointers.
|
---|
279 | */
|
---|
280 | typedef PRStatus
|
---|
281 | (PR_CALLBACK *PRScanStackFun)(PRThread* t,
|
---|
282 | void** baseAddr, PRUword count, void* closure);
|
---|
283 |
|
---|
284 | /*
|
---|
285 | ** Applies scanFun to all contiguous groups of potential pointers
|
---|
286 | ** within a thread. This includes the stack, registers, and thread-local
|
---|
287 | ** data. If scanFun returns a status value other than PR_SUCCESS the scan
|
---|
288 | ** is aborted, and the status value is returned.
|
---|
289 | */
|
---|
290 | NSPR_API(PRStatus)
|
---|
291 | PR_ThreadScanStackPointers(PRThread* t,
|
---|
292 | PRScanStackFun scanFun, void* scanClosure);
|
---|
293 |
|
---|
294 | /*
|
---|
295 | ** Calls PR_ThreadScanStackPointers for every thread.
|
---|
296 | */
|
---|
297 | NSPR_API(PRStatus)
|
---|
298 | PR_ScanStackPointers(PRScanStackFun scanFun, void* scanClosure);
|
---|
299 |
|
---|
300 | /*
|
---|
301 | ** Returns a conservative estimate on the amount of stack space left
|
---|
302 | ** on a thread in bytes, sufficient for making decisions about whether
|
---|
303 | ** to continue recursing or not.
|
---|
304 | */
|
---|
305 | NSPR_API(PRUword)
|
---|
306 | PR_GetStackSpaceLeft(PRThread* t);
|
---|
307 |
|
---|
308 | /*---------------------------------------------------------------------------
|
---|
309 | ** THREAD CPU PRIVATE FUNCTIONS
|
---|
310 | ---------------------------------------------------------------------------*/
|
---|
311 |
|
---|
312 | /*
|
---|
313 | ** Get a pointer to the primordial CPU.
|
---|
314 | */
|
---|
315 | NSPR_API(struct _PRCPU *) _PR_GetPrimordialCPU(void);
|
---|
316 |
|
---|
317 | /*---------------------------------------------------------------------------
|
---|
318 | ** THREAD SYNCHRONIZATION PRIVATE FUNCTIONS
|
---|
319 | ---------------------------------------------------------------------------*/
|
---|
320 |
|
---|
321 | /*
|
---|
322 | ** Create a new named monitor (named for debugging purposes).
|
---|
323 | ** Monitors are re-entrant locks with a built-in condition variable.
|
---|
324 | **
|
---|
325 | ** This may fail if memory is tight or if some operating system resource
|
---|
326 | ** is low.
|
---|
327 | */
|
---|
328 | NSPR_API(PRMonitor*) PR_NewNamedMonitor(const char* name);
|
---|
329 |
|
---|
330 | /*
|
---|
331 | ** Test and then lock the lock if it's not already locked by some other
|
---|
332 | ** thread. Return PR_FALSE if some other thread owned the lock at the
|
---|
333 | ** time of the call.
|
---|
334 | */
|
---|
335 | NSPR_API(PRBool) PR_TestAndLock(PRLock *lock);
|
---|
336 |
|
---|
337 | /*
|
---|
338 | ** Test and then enter the mutex associated with the monitor if it's not
|
---|
339 | ** already entered by some other thread. Return PR_FALSE if some other
|
---|
340 | ** thread owned the mutex at the time of the call.
|
---|
341 | */
|
---|
342 | NSPR_API(PRBool) PR_TestAndEnterMonitor(PRMonitor *mon);
|
---|
343 |
|
---|
344 | /*
|
---|
345 | ** Return the number of times that the current thread has entered the
|
---|
346 | ** mutex. Returns zero if the current thread has not entered the mutex.
|
---|
347 | */
|
---|
348 | NSPR_API(PRIntn) PR_GetMonitorEntryCount(PRMonitor *mon);
|
---|
349 |
|
---|
350 | /*
|
---|
351 | ** Just like PR_CEnterMonitor except that if the monitor is owned by
|
---|
352 | ** another thread NULL is returned.
|
---|
353 | */
|
---|
354 | NSPR_API(PRMonitor*) PR_CTestAndEnterMonitor(void *address);
|
---|
355 |
|
---|
356 | /*---------------------------------------------------------------------------
|
---|
357 | ** PLATFORM-SPECIFIC THREAD SYNCHRONIZATION FUNCTIONS
|
---|
358 | ---------------------------------------------------------------------------*/
|
---|
359 | #if defined(XP_MAC)
|
---|
360 |
|
---|
361 | NSPR_API(void) PR_Mac_WaitForAsyncNotify(PRIntervalTime timeout);
|
---|
362 | NSPR_API(void) PR_Mac_PostAsyncNotify(PRThread *thread);
|
---|
363 |
|
---|
364 | #endif /* XP_MAC */
|
---|
365 |
|
---|
366 | /*---------------------------------------------------------------------------
|
---|
367 | ** PLATFORM-SPECIFIC INITIALIZATION FUNCTIONS
|
---|
368 | ---------------------------------------------------------------------------*/
|
---|
369 | #if defined(IRIX)
|
---|
370 | /*
|
---|
371 | ** Irix specific initialization funtion to be called before PR_Init
|
---|
372 | ** is called by the application. Sets the CONF_INITUSERS and CONF_INITSIZE
|
---|
373 | ** attributes of the shared arena set up by nspr.
|
---|
374 | **
|
---|
375 | ** The environment variables _NSPR_IRIX_INITUSERS and _NSPR_IRIX_INITSIZE
|
---|
376 | ** can also be used to set these arena attributes. If _NSPR_IRIX_INITUSERS
|
---|
377 | ** is set, but not _NSPR_IRIX_INITSIZE, the value of the CONF_INITSIZE
|
---|
378 | ** attribute of the nspr arena is scaled as a function of the
|
---|
379 | ** _NSPR_IRIX_INITUSERS value.
|
---|
380 | **
|
---|
381 | ** If the _PR_Irix_Set_Arena_Params() is called in addition to setting the
|
---|
382 | ** environment variables, the values of the environment variables are used.
|
---|
383 | **
|
---|
384 | */
|
---|
385 | NSPR_API(void) _PR_Irix_Set_Arena_Params(PRInt32 initusers, PRInt32 initsize);
|
---|
386 |
|
---|
387 | #endif /* IRIX */
|
---|
388 |
|
---|
389 | #if defined(XP_OS2)
|
---|
390 | /*
|
---|
391 | ** These functions need to be called at the start and end of a thread.
|
---|
392 | ** An EXCEPTIONREGISTRATIONRECORD must be declared on the stack and its
|
---|
393 | ** address passed to the two functions.
|
---|
394 | */
|
---|
395 | NSPR_API(void) PR_OS2_SetFloatExcpHandler(EXCEPTIONREGISTRATIONRECORD* e);
|
---|
396 | NSPR_API(void) PR_OS2_UnsetFloatExcpHandler(EXCEPTIONREGISTRATIONRECORD* e);
|
---|
397 | #endif /* XP_OS2 */
|
---|
398 |
|
---|
399 | /* I think PR_GetMonitorEntryCount is useless. All you really want is this... */
|
---|
400 | #define PR_InMonitor(m) (PR_GetMonitorEntryCount(m) > 0)
|
---|
401 |
|
---|
402 | /*---------------------------------------------------------------------------
|
---|
403 | ** Special X-Lock hack for client
|
---|
404 | ---------------------------------------------------------------------------*/
|
---|
405 |
|
---|
406 | #ifdef XP_UNIX
|
---|
407 | extern void PR_XLock(void);
|
---|
408 | extern void PR_XUnlock(void);
|
---|
409 | extern PRBool PR_XIsLocked(void);
|
---|
410 | #endif /* XP_UNIX */
|
---|
411 |
|
---|
412 | PR_END_EXTERN_C
|
---|
413 |
|
---|
414 | #endif /* pprthred_h___ */
|
---|