Fix Centurion name.
[0ad.git] / libraries / source / spidermonkey / include-win32-release / nspr / private / pprthred.h
blobf772f1c28ca73e361937f1f1a174e5f1472266d8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef pprthred_h___
7 #define pprthred_h___
9 /*
10 ** API for PR private functions. These calls are to be used by internal
11 ** developers only.
13 #include "nspr.h"
15 #if defined(XP_OS2)
16 #define INCL_DOS
17 #define INCL_DOSERRORS
18 #define INCL_WIN
19 #include <os2.h>
20 #endif
22 PR_BEGIN_EXTERN_C
24 /*---------------------------------------------------------------------------
25 ** THREAD PRIVATE FUNCTIONS
26 ---------------------------------------------------------------------------*/
29 ** Associate a thread object with an existing native thread.
30 ** "type" is the type of thread object to attach
31 ** "priority" is the priority to assign to the thread
32 ** "stack" defines the shape of the threads stack
34 ** This can return NULL if some kind of error occurs, or if memory is
35 ** tight. This call invokes "start(obj,arg)" and returns when the
36 ** function returns. The thread object is automatically destroyed.
38 ** This call is not normally needed unless you create your own native
39 ** thread. PR_Init does this automatically for the primordial thread.
41 NSPR_API(PRThread*) PR_AttachThread(PRThreadType type,
42 PRThreadPriority priority,
43 PRThreadStack *stack);
46 ** Detach the nspr thread from the currently executing native thread.
47 ** The thread object will be destroyed and all related data attached
48 ** to it. The exit procs will be invoked.
50 ** This call is not normally needed unless you create your own native
51 ** thread. PR_Exit will automatially detach the nspr thread object
52 ** created by PR_Init for the primordial thread.
54 ** This call returns after the nspr thread object is destroyed.
56 NSPR_API(void) PR_DetachThread(void);
59 ** Get the id of the named thread. Each thread is assigned a unique id
60 ** when it is created or attached.
62 NSPR_API(PRUint32) PR_GetThreadID(PRThread *thread);
65 ** Set the procedure that is called when a thread is dumped. The procedure
66 ** will be applied to the argument, arg, when called. Setting the procedure
67 ** to NULL effectively removes it.
69 typedef void (*PRThreadDumpProc)(PRFileDesc *fd, PRThread *t, void *arg);
70 NSPR_API(void) PR_SetThreadDumpProc(
71 PRThread* thread, PRThreadDumpProc dump, void *arg);
74 ** Get this thread's affinity mask. The affinity mask is a 32 bit quantity
75 ** marking a bit for each processor this process is allowed to run on.
76 ** The processor mask is returned in the mask argument.
77 ** The least-significant-bit represents processor 0.
79 ** Returns 0 on success, -1 on failure.
81 NSPR_API(PRInt32) PR_GetThreadAffinityMask(PRThread *thread, PRUint32 *mask);
84 ** Set this thread's affinity mask.
86 ** Returns 0 on success, -1 on failure.
88 NSPR_API(PRInt32) PR_SetThreadAffinityMask(PRThread *thread, PRUint32 mask );
91 ** Set the default CPU Affinity mask.
94 NSPR_API(PRInt32) PR_SetCPUAffinityMask(PRUint32 mask);
97 ** Show status of all threads to standard error output.
99 NSPR_API(void) PR_ShowStatus(void);
102 ** Set thread recycle mode to on (1) or off (0)
104 NSPR_API(void) PR_SetThreadRecycleMode(PRUint32 flag);
107 /*---------------------------------------------------------------------------
108 ** THREAD PRIVATE FUNCTIONS FOR GARBAGE COLLECTIBLE THREADS
109 ---------------------------------------------------------------------------*/
112 ** Only Garbage collectible threads participate in resume all, suspend all and
113 ** enumeration operations. They are also different during creation when
114 ** platform specific action may be needed (For example, all Solaris GC able
115 ** threads are bound threads).
119 ** Same as PR_CreateThread except that the thread is marked as garbage
120 ** collectible.
122 NSPR_API(PRThread*) PR_CreateThreadGCAble(PRThreadType type,
123 void (*start)(void *arg),
124 void *arg,
125 PRThreadPriority priority,
126 PRThreadScope scope,
127 PRThreadState state,
128 PRUint32 stackSize);
131 ** Same as PR_AttachThread except that the thread being attached is marked as
132 ** garbage collectible.
134 NSPR_API(PRThread*) PR_AttachThreadGCAble(PRThreadType type,
135 PRThreadPriority priority,
136 PRThreadStack *stack);
139 ** Mark the thread as garbage collectible.
141 NSPR_API(void) PR_SetThreadGCAble(void);
144 ** Unmark the thread as garbage collectible.
146 NSPR_API(void) PR_ClearThreadGCAble(void);
149 ** This routine prevents all other GC able threads from running. This call is needed by
150 ** the garbage collector.
152 NSPR_API(void) PR_SuspendAll(void);
155 ** This routine unblocks all other GC able threads that were suspended from running by
156 ** PR_SuspendAll(). This call is needed by the garbage collector.
158 NSPR_API(void) PR_ResumeAll(void);
161 ** Return the thread stack pointer of the given thread.
162 ** Needed by the garbage collector.
164 NSPR_API(void *) PR_GetSP(PRThread *thread);
167 ** Save the registers that the GC would find interesting into the thread
168 ** "t". isCurrent will be non-zero if the thread state that is being
169 ** saved is the currently executing thread. Return the address of the
170 ** first register to be scanned as well as the number of registers to
171 ** scan in "np".
173 ** If "isCurrent" is non-zero then it is allowed for the thread context
174 ** area to be used as scratch storage to hold just the registers
175 ** necessary for scanning.
177 ** This function simply calls the internal function _MD_HomeGCRegisters().
179 NSPR_API(PRWord *) PR_GetGCRegisters(PRThread *t, int isCurrent, int *np);
182 ** (Get|Set)ExecutionEnvironent
184 ** Used by Java to associate it's execution environment so garbage collector
185 ** can find it. If return is NULL, then it's probably not a collectable thread.
187 ** There's no locking required around these calls.
189 NSPR_API(void*) GetExecutionEnvironment(PRThread *thread);
190 NSPR_API(void) SetExecutionEnvironment(PRThread* thread, void *environment);
193 ** Enumeration function that applies "func(thread,i,arg)" to each active
194 ** thread in the process. The enumerator returns PR_SUCCESS if the enumeration
195 ** should continue, any other value is considered failure, and enumeration
196 ** stops, returning the failure value from PR_EnumerateThreads.
197 ** Needed by the garbage collector.
199 typedef PRStatus (PR_CALLBACK *PREnumerator)(PRThread *t, int i, void *arg);
200 NSPR_API(PRStatus) PR_EnumerateThreads(PREnumerator func, void *arg);
203 ** Signature of a thread stack scanning function. It is applied to every
204 ** contiguous group of potential pointers within a thread. Count denotes the
205 ** number of pointers.
207 typedef PRStatus
208 (PR_CALLBACK *PRScanStackFun)(PRThread* t,
209 void** baseAddr, PRUword count, void* closure);
212 ** Applies scanFun to all contiguous groups of potential pointers
213 ** within a thread. This includes the stack, registers, and thread-local
214 ** data. If scanFun returns a status value other than PR_SUCCESS the scan
215 ** is aborted, and the status value is returned.
217 NSPR_API(PRStatus)
218 PR_ThreadScanStackPointers(PRThread* t,
219 PRScanStackFun scanFun, void* scanClosure);
222 ** Calls PR_ThreadScanStackPointers for every thread.
224 NSPR_API(PRStatus)
225 PR_ScanStackPointers(PRScanStackFun scanFun, void* scanClosure);
228 ** Returns a conservative estimate on the amount of stack space left
229 ** on a thread in bytes, sufficient for making decisions about whether
230 ** to continue recursing or not.
232 NSPR_API(PRUword)
233 PR_GetStackSpaceLeft(PRThread* t);
235 /*---------------------------------------------------------------------------
236 ** THREAD CPU PRIVATE FUNCTIONS
237 ---------------------------------------------------------------------------*/
240 ** Get a pointer to the primordial CPU.
242 NSPR_API(struct _PRCPU *) _PR_GetPrimordialCPU(void);
244 /*---------------------------------------------------------------------------
245 ** THREAD SYNCHRONIZATION PRIVATE FUNCTIONS
246 ---------------------------------------------------------------------------*/
249 ** Create a new named monitor (named for debugging purposes).
250 ** Monitors are re-entrant locks with a built-in condition variable.
252 ** This may fail if memory is tight or if some operating system resource
253 ** is low.
255 NSPR_API(PRMonitor*) PR_NewNamedMonitor(const char* name);
258 ** Test and then lock the lock if it's not already locked by some other
259 ** thread. Return PR_FALSE if some other thread owned the lock at the
260 ** time of the call.
262 NSPR_API(PRBool) PR_TestAndLock(PRLock *lock);
265 ** Test and then enter the mutex associated with the monitor if it's not
266 ** already entered by some other thread. Return PR_FALSE if some other
267 ** thread owned the mutex at the time of the call.
269 NSPR_API(PRBool) PR_TestAndEnterMonitor(PRMonitor *mon);
272 ** Return the number of times that the current thread has entered the
273 ** mutex. Returns zero if the current thread has not entered the mutex.
275 NSPR_API(PRIntn) PR_GetMonitorEntryCount(PRMonitor *mon);
278 ** Just like PR_CEnterMonitor except that if the monitor is owned by
279 ** another thread NULL is returned.
281 NSPR_API(PRMonitor*) PR_CTestAndEnterMonitor(void *address);
283 /*---------------------------------------------------------------------------
284 ** PLATFORM-SPECIFIC INITIALIZATION FUNCTIONS
285 ---------------------------------------------------------------------------*/
286 #if defined(XP_OS2)
288 ** These functions need to be called at the start and end of a thread.
289 ** An EXCEPTIONREGISTRATIONRECORD must be declared on the stack and its
290 ** address passed to the two functions.
292 NSPR_API(void) PR_OS2_SetFloatExcpHandler(EXCEPTIONREGISTRATIONRECORD* e);
293 NSPR_API(void) PR_OS2_UnsetFloatExcpHandler(EXCEPTIONREGISTRATIONRECORD* e);
294 #endif /* XP_OS2 */
296 /* I think PR_GetMonitorEntryCount is useless. All you really want is this... */
297 #define PR_InMonitor(m) (PR_GetMonitorEntryCount(m) > 0)
299 /*---------------------------------------------------------------------------
300 ** Special X-Lock hack for client
301 ---------------------------------------------------------------------------*/
303 #ifdef XP_UNIX
304 extern void PR_XLock(void);
305 extern void PR_XUnlock(void);
306 extern PRBool PR_XIsLocked(void);
307 #endif /* XP_UNIX */
309 PR_END_EXTERN_C
311 #endif /* pprthred_h___ */