15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * The contents of this file are subject to the Mozilla Public 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * License Version 1.1 (the "License"); you may not use this file 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * except in compliance with the License. You may obtain a copy of 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * the License at http://www.mozilla.org/MPL/ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Software distributed under the License is distributed on an "AS 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * implied. See the License for the specific language governing 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * rights and limitations under the License. 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * The Original Code is the Netscape Portable Runtime (NSPR). 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * The Initial Developer of the Original Code is Netscape 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Communications Corporation. Portions created by Netscape are 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Copyright (C) 1998-2000 Netscape Communications Corporation. All 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Rights Reserved. 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Contributor(s): 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Alternatively, the contents of this file may be used under the 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * terms of the GNU General Public License Version 2 or later (the 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * "GPL"), in which case the provisions of the GPL are applicable 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * instead of those above. If you wish to allow use of your 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * version of this file only under the terms of the GPL and not to 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * allow others to use your version of this file under the MPL, 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * indicate your decision by deleting the provisions above and 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * replace them with the notice and other provisions required by 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * the GPL. If you do not delete the provisions above, a recipient 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * may use your version of this file under either the MPL or the 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * GPL. 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef pprthred_h___ 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define pprthred_h___ 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** API for PR private functions. These calls are to be used by internal 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** developers only. 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "nspr.h" 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(XP_OS2) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define INCL_DOS 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define INCL_DOSERRORS 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define INCL_WIN 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <os2.h> 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PR_BEGIN_EXTERN_C 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*--------------------------------------------------------------------------- 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** THREAD PRIVATE FUNCTIONS 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)---------------------------------------------------------------------------*/ 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Associate a thread object with an existing native thread. 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** "type" is the type of thread object to attach 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** "priority" is the priority to assign to the thread 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** "stack" defines the shape of the threads stack 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This can return NULL if some kind of error occurs, or if memory is 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** tight. This call invokes "start(obj,arg)" and returns when the 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** function returns. The thread object is automatically destroyed. 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This call is not normally needed unless you create your own native 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** thread. PR_Init does this automatically for the primordial thread. 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRThread*) PR_AttachThread(PRThreadType type, 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PRThreadPriority priority, 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PRThreadStack *stack); 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Detach the nspr thread from the currently executing native thread. 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The thread object will be destroyed and all related data attached 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to it. The exit procs will be invoked. 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This call is not normally needed unless you create your own native 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** thread. PR_Exit will automatially detach the nspr thread object 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** created by PR_Init for the primordial thread. 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This call returns after the nspr thread object is destroyed. 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void) PR_DetachThread(void); 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Get the id of the named thread. Each thread is assigned a unique id 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** when it is created or attached. 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRUint32) PR_GetThreadID(PRThread *thread); 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Set the procedure that is called when a thread is dumped. The procedure 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** will be applied to the argument, arg, when called. Setting the procedure 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to NULL effectively removes it. 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef void (*PRThreadDumpProc)(PRFileDesc *fd, PRThread *t, void *arg); 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void) PR_SetThreadDumpProc( 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PRThread* thread, PRThreadDumpProc dump, void *arg); 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Get this thread's affinity mask. The affinity mask is a 32 bit quantity 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** marking a bit for each processor this process is allowed to run on. 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The processor mask is returned in the mask argument. 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The least-significant-bit represents processor 0. 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Returns 0 on success, -1 on failure. 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRInt32) PR_GetThreadAffinityMask(PRThread *thread, PRUint32 *mask); 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Set this thread's affinity mask. 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Returns 0 on success, -1 on failure. 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRInt32) PR_SetThreadAffinityMask(PRThread *thread, PRUint32 mask ); 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Set the default CPU Affinity mask. 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRInt32) PR_SetCPUAffinityMask(PRUint32 mask); 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Show status of all threads to standard error output. 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void) PR_ShowStatus(void); 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Set thread recycle mode to on (1) or off (0) 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void) PR_SetThreadRecycleMode(PRUint32 flag); 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*--------------------------------------------------------------------------- 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** THREAD PRIVATE FUNCTIONS FOR GARBAGE COLLECTIBLE THREADS 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)---------------------------------------------------------------------------*/ 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Only Garbage collectible threads participate in resume all, suspend all and 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** enumeration operations. They are also different during creation when 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** platform specific action may be needed (For example, all Solaris GC able 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** threads are bound threads). 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Same as PR_CreateThread except that the thread is marked as garbage 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** collectible. 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRThread*) PR_CreateThreadGCAble(PRThreadType type, 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void (*start)(void *arg), 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void *arg, 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PRThreadPriority priority, 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PRThreadScope scope, 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PRThreadState state, 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PRUint32 stackSize); 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Same as PR_AttachThread except that the thread being attached is marked as 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** garbage collectible. 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRThread*) PR_AttachThreadGCAble(PRThreadType type, 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PRThreadPriority priority, 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PRThreadStack *stack); 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Mark the thread as garbage collectible. 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void) PR_SetThreadGCAble(void); 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Unmark the thread as garbage collectible. 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void) PR_ClearThreadGCAble(void); 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This routine prevents all other GC able threads from running. This call is needed by 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the garbage collector. 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void) PR_SuspendAll(void); 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This routine unblocks all other GC able threads that were suspended from running by 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** PR_SuspendAll(). This call is needed by the garbage collector. 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void) PR_ResumeAll(void); 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Return the thread stack pointer of the given thread. 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Needed by the garbage collector. 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void *) PR_GetSP(PRThread *thread); 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Save the registers that the GC would find interesting into the thread 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** "t". isCurrent will be non-zero if the thread state that is being 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** saved is the currently executing thread. Return the address of the 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** first register to be scanned as well as the number of registers to 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** scan in "np". 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If "isCurrent" is non-zero then it is allowed for the thread context 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** area to be used as scratch storage to hold just the registers 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** necessary for scanning. 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This function simply calls the internal function _MD_HomeGCRegisters(). 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRWord *) PR_GetGCRegisters(PRThread *t, int isCurrent, int *np); 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** (Get|Set)ExecutionEnvironent 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Used by Java to associate it's execution environment so garbage collector 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** can find it. If return is NULL, then it's probably not a collectable thread. 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** There's no locking required around these calls. 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void*) GetExecutionEnvironment(PRThread *thread); 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void) SetExecutionEnvironment(PRThread* thread, void *environment); 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Enumeration function that applies "func(thread,i,arg)" to each active 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** thread in the process. The enumerator returns PR_SUCCESS if the enumeration 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** should continue, any other value is considered failure, and enumeration 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** stops, returning the failure value from PR_EnumerateThreads. 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Needed by the garbage collector. 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef PRStatus (PR_CALLBACK *PREnumerator)(PRThread *t, int i, void *arg); 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRStatus) PR_EnumerateThreads(PREnumerator func, void *arg); 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Signature of a thread stack scanning function. It is applied to every 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** contiguous group of potential pointers within a thread. Count denotes the 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** number of pointers. 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef PRStatus 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)(PR_CALLBACK *PRScanStackFun)(PRThread* t, 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void** baseAddr, PRUword count, void* closure); 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Applies scanFun to all contiguous groups of potential pointers 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** within a thread. This includes the stack, registers, and thread-local 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** data. If scanFun returns a status value other than PR_SUCCESS the scan 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is aborted, and the status value is returned. 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRStatus) 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PR_ThreadScanStackPointers(PRThread* t, 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PRScanStackFun scanFun, void* scanClosure); 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Calls PR_ThreadScanStackPointers for every thread. 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRStatus) 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PR_ScanStackPointers(PRScanStackFun scanFun, void* scanClosure); 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Returns a conservative estimate on the amount of stack space left 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** on a thread in bytes, sufficient for making decisions about whether 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to continue recursing or not. 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRUword) 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PR_GetStackSpaceLeft(PRThread* t); 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*--------------------------------------------------------------------------- 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** THREAD CPU PRIVATE FUNCTIONS 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)---------------------------------------------------------------------------*/ 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Get a pointer to the primordial CPU. 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(struct _PRCPU *) _PR_GetPrimordialCPU(void); 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*--------------------------------------------------------------------------- 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** THREAD SYNCHRONIZATION PRIVATE FUNCTIONS 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)---------------------------------------------------------------------------*/ 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Create a new named monitor (named for debugging purposes). 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Monitors are re-entrant locks with a built-in condition variable. 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** This may fail if memory is tight or if some operating system resource 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is low. 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRMonitor*) PR_NewNamedMonitor(const char* name); 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Test and then lock the lock if it's not already locked by some other 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** thread. Return PR_FALSE if some other thread owned the lock at the 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** time of the call. 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRBool) PR_TestAndLock(PRLock *lock); 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Test and then enter the mutex associated with the monitor if it's not 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** already entered by some other thread. Return PR_FALSE if some other 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** thread owned the mutex at the time of the call. 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRBool) PR_TestAndEnterMonitor(PRMonitor *mon); 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Return the number of times that the current thread has entered the 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** mutex. Returns zero if the current thread has not entered the mutex. 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRIntn) PR_GetMonitorEntryCount(PRMonitor *mon); 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Just like PR_CEnterMonitor except that if the monitor is owned by 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** another thread NULL is returned. 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRMonitor*) PR_CTestAndEnterMonitor(void *address); 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*--------------------------------------------------------------------------- 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** PLATFORM-SPECIFIC THREAD SYNCHRONIZATION FUNCTIONS 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)---------------------------------------------------------------------------*/ 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(XP_MAC) 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void) PR_Mac_WaitForAsyncNotify(PRIntervalTime timeout); 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void) PR_Mac_PostAsyncNotify(PRThread *thread); 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif /* XP_MAC */ 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*--------------------------------------------------------------------------- 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** PLATFORM-SPECIFIC INITIALIZATION FUNCTIONS 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)---------------------------------------------------------------------------*/ 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(IRIX) 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Irix specific initialization funtion to be called before PR_Init 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is called by the application. Sets the CONF_INITUSERS and CONF_INITSIZE 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** attributes of the shared arena set up by nspr. 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** The environment variables _NSPR_IRIX_INITUSERS and _NSPR_IRIX_INITSIZE 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** can also be used to set these arena attributes. If _NSPR_IRIX_INITUSERS 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** is set, but not _NSPR_IRIX_INITSIZE, the value of the CONF_INITSIZE 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** attribute of the nspr arena is scaled as a function of the 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** _NSPR_IRIX_INITUSERS value. 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If the _PR_Irix_Set_Arena_Params() is called in addition to setting the 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** environment variables, the values of the environment variables are used. 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void) _PR_Irix_Set_Arena_Params(PRInt32 initusers, PRInt32 initsize); 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif /* IRIX */ 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(XP_OS2) 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** These functions need to be called at the start and end of a thread. 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** An EXCEPTIONREGISTRATIONRECORD must be declared on the stack and its 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** address passed to the two functions. 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/ 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void) PR_OS2_SetFloatExcpHandler(EXCEPTIONREGISTRATIONRECORD* e); 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void) PR_OS2_UnsetFloatExcpHandler(EXCEPTIONREGISTRATIONRECORD* e); 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif /* XP_OS2 */ 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* I think PR_GetMonitorEntryCount is useless. All you really want is this... */ 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define PR_InMonitor(m) (PR_GetMonitorEntryCount(m) > 0) 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*--------------------------------------------------------------------------- 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Special X-Lock hack for client 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)---------------------------------------------------------------------------*/ 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef XP_UNIX 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern void PR_XLock(void); 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern void PR_XUnlock(void); 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern PRBool PR_XIsLocked(void); 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif /* XP_UNIX */ 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PR_END_EXTERN_C 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif /* pprthred_h___ */ 371