📄 primpl.h
字号:
#else /* XP_MAC */#define _PR_INTSOFF(_is) \ PR_BEGIN_MACRO \ (_is) = _PR_MD_GET_INTSOFF(); \ _PR_MD_SET_INTSOFF(1); \ PR_END_MACRO#endif /* XP_MAC */#define _PR_FAST_INTSON(_is) \ PR_BEGIN_MACRO \ _PR_MD_SET_INTSOFF(_is); \ PR_END_MACRO#define _PR_INTSON(_is) \ PR_BEGIN_MACRO \ if ((_is == 0) && (_PR_MD_CURRENT_CPU())->u.bits) \ _PR_IntsOn((_PR_MD_CURRENT_CPU())); \ _PR_MD_SET_INTSOFF(_is); \ PR_END_MACRO#ifdef _PR_LOCAL_THREADS_ONLY #define _PR_IS_NATIVE_THREAD(thread) 0#define _PR_THREAD_LOCK(_thread)#define _PR_THREAD_UNLOCK(_thread)#define _PR_RUNQ_LOCK(cpu)#define _PR_RUNQ_UNLOCK(cpu)#define _PR_SLEEPQ_LOCK(thread)#define _PR_SLEEPQ_UNLOCK(thread)#define _PR_MISCQ_LOCK(thread)#define _PR_MISCQ_UNLOCK(thread)#define _PR_CPU_LIST_LOCK()#define _PR_CPU_LIST_UNLOCK()#define _PR_ADD_RUNQ(_thread, _cpu, _pri) \ PR_BEGIN_MACRO \ PR_APPEND_LINK(&(_thread)->links, &_PR_RUNQ(_cpu)[_pri]); \ _PR_RUNQREADYMASK(_cpu) |= (1L << _pri); \ PR_END_MACRO#define _PR_DEL_RUNQ(_thread) \ PR_BEGIN_MACRO \ _PRCPU *_cpu = _thread->cpu; \ PRInt32 _pri = _thread->priority; \ PR_REMOVE_LINK(&(_thread)->links); \ if (PR_CLIST_IS_EMPTY(&_PR_RUNQ(_cpu)[_pri])) \ _PR_RUNQREADYMASK(_cpu) &= ~(1L << _pri); \ PR_END_MACRO#define _PR_ADD_SLEEPQ(_thread, _timeout) \ _PR_AddSleepQ(_thread, _timeout); #define _PR_DEL_SLEEPQ(_thread, _propogate) \ _PR_DelSleepQ(_thread, _propogate); #define _PR_ADD_JOINQ(_thread, _cpu) \ PR_APPEND_LINK(&(_thread)->links, &_PR_WAITINGTOJOINQ(_cpu));#define _PR_DEL_JOINQ(_thread) \ PR_REMOVE_LINK(&(_thread)->links);#define _PR_ADD_SUSPENDQ(_thread, _cpu) \ PR_APPEND_LINK(&(_thread)->links, &_PR_SUSPENDQ(_cpu));#define _PR_DEL_SUSPENDQ(_thread) \ PR_REMOVE_LINK(&(_thread)->links);#define _PR_THREAD_SWITCH_CPU(_thread, _newCPU)#define _PR_IS_NATIVE_THREAD_SUPPORTED() 0#else /* _PR_LOCAL_THREADS_ONLY *//* These are for the "combined" thread model */#define _PR_THREAD_LOCK(_thread) \ _PR_MD_LOCK(&(_thread)->threadLock);#define _PR_THREAD_UNLOCK(_thread) \ _PR_MD_UNLOCK(&(_thread)->threadLock);#define _PR_RUNQ_LOCK(_cpu) \ PR_BEGIN_MACRO \ _PR_MD_LOCK(&(_cpu)->queue->runQLock );\ PR_END_MACRO #define _PR_RUNQ_UNLOCK(_cpu) \ PR_BEGIN_MACRO \ _PR_MD_UNLOCK(&(_cpu)->queue->runQLock );\ PR_END_MACRO#define _PR_SLEEPQ_LOCK(_cpu) \ _PR_MD_LOCK(&(_cpu)->queue->sleepQLock );#define _PR_SLEEPQ_UNLOCK(_cpu) \ _PR_MD_UNLOCK(&(_cpu)->queue->sleepQLock );#define _PR_MISCQ_LOCK(_cpu) \ _PR_MD_LOCK(&(_cpu)->queue->miscQLock );#define _PR_MISCQ_UNLOCK(_cpu) \ _PR_MD_UNLOCK(&(_cpu)->queue->miscQLock );#define _PR_CPU_LIST_LOCK() _PR_MD_LOCK(&_pr_cpuLock)#define _PR_CPU_LIST_UNLOCK() _PR_MD_UNLOCK(&_pr_cpuLock)#define QUEUE_RUN 0x1#define QUEUE_SLEEP 0x2#define QUEUE_JOIN 0x4#define QUEUE_SUSPEND 0x8#define QUEUE_LOCK 0x10#define _PR_ADD_RUNQ(_thread, _cpu, _pri) \ PR_BEGIN_MACRO \ PR_APPEND_LINK(&(_thread)->links, &_PR_RUNQ(_cpu)[_pri]); \ _PR_RUNQREADYMASK(_cpu) |= (1L << _pri); \ PR_ASSERT((_thread)->queueCount == 0); \ (_thread)->queueCount = QUEUE_RUN; \ PR_END_MACRO#define _PR_DEL_RUNQ(_thread) \ PR_BEGIN_MACRO \ _PRCPU *_cpu = _thread->cpu; \ PRInt32 _pri = _thread->priority; \ PR_REMOVE_LINK(&(_thread)->links); \ if (PR_CLIST_IS_EMPTY(&_PR_RUNQ(_cpu)[_pri])) \ _PR_RUNQREADYMASK(_cpu) &= ~(1L << _pri); \ PR_ASSERT((_thread)->queueCount == QUEUE_RUN);\ (_thread)->queueCount = 0; \ PR_END_MACRO#define _PR_ADD_SLEEPQ(_thread, _timeout) \ PR_ASSERT((_thread)->queueCount == 0); \ (_thread)->queueCount = QUEUE_SLEEP; \ _PR_AddSleepQ(_thread, _timeout); #define _PR_DEL_SLEEPQ(_thread, _propogate) \ PR_ASSERT((_thread)->queueCount == QUEUE_SLEEP);\ (_thread)->queueCount = 0; \ _PR_DelSleepQ(_thread, _propogate); #define _PR_ADD_JOINQ(_thread, _cpu) \ PR_ASSERT((_thread)->queueCount == 0); \ (_thread)->queueCount = QUEUE_JOIN; \ PR_APPEND_LINK(&(_thread)->links, &_PR_WAITINGTOJOINQ(_cpu));#define _PR_DEL_JOINQ(_thread) \ PR_ASSERT((_thread)->queueCount == QUEUE_JOIN);\ (_thread)->queueCount = 0; \ PR_REMOVE_LINK(&(_thread)->links);#define _PR_ADD_SUSPENDQ(_thread, _cpu) \ PR_ASSERT((_thread)->queueCount == 0); \ (_thread)->queueCount = QUEUE_SUSPEND; \ PR_APPEND_LINK(&(_thread)->links, &_PR_SUSPENDQ(_cpu));#define _PR_DEL_SUSPENDQ(_thread) \ PR_ASSERT((_thread)->queueCount == QUEUE_SUSPEND);\ (_thread)->queueCount = 0; \ PR_REMOVE_LINK(&(_thread)->links);#define _PR_THREAD_SWITCH_CPU(_thread, _newCPU) \ (_thread)->cpu = (_newCPU);#define _PR_IS_NATIVE_THREAD(thread) (thread->flags & _PR_GLOBAL_SCOPE)#define _PR_IS_NATIVE_THREAD_SUPPORTED() 1#endif /* _PR_LOCAL_THREADS_ONLY */#endif /* _PR_GLOBAL_THREADS_ONLY */#define _PR_SET_RESCHED_FLAG() _PR_MD_CURRENT_CPU()->u.missed[3] = 1#define _PR_CLEAR_RESCHED_FLAG() _PR_MD_CURRENT_CPU()->u.missed[3] = 0extern _PRInterruptTable _pr_interruptTable[];/* Bits for _pr_interruptState.u.missed[0,1] */#define _PR_MISSED_CLOCK 0x1#define _PR_MISSED_IO 0x2#define _PR_MISSED_CHILD 0x4extern void _PR_IntsOn(_PRCPU *cpu);NSPR_API(void) _PR_WakeupCPU(void);NSPR_API(void) _PR_PauseCPU(void);/************************************************************************/#define _PR_LOCK_LOCK(_lock) \ _PR_MD_LOCK(&(_lock)->ilock);#define _PR_LOCK_UNLOCK(_lock) \ _PR_MD_UNLOCK(&(_lock)->ilock); extern void _PR_UnblockLockWaiter(PRLock *lock);#define _PR_LOCK_PTR(_qp) \ ((PRLock*) ((char*) (_qp) - offsetof(PRLock,links)))/************************************************************************/#define _PR_CVAR_LOCK(_cvar) \ _PR_MD_LOCK(&(_cvar)->ilock); #define _PR_CVAR_UNLOCK(_cvar) \ _PR_MD_UNLOCK(&(_cvar)->ilock);extern PRStatus _PR_WaitCondVar( PRThread *thread, PRCondVar *cvar, PRLock *lock, PRIntervalTime timeout);extern PRUint32 _PR_CondVarToString(PRCondVar *cvar, char *buf, PRUint32 buflen);NSPR_API(void) _PR_Notify(PRMonitor *mon, PRBool all, PRBool sticky);/* PRThread.flags */#define _PR_SYSTEM 0x01#define _PR_INTERRUPT 0x02#define _PR_ATTACHED 0x04 /* created via PR_AttachThread */#define _PR_PRIMORDIAL 0x08 /* the thread that called PR_Init */#define _PR_ON_SLEEPQ 0x10 /* thread is on the sleepQ */#define _PR_ON_PAUSEQ 0x20 /* thread is on the pauseQ */#define _PR_SUSPENDING 0x40 /* thread wants to suspend */#define _PR_GLOBAL_SCOPE 0x80 /* thread is global scope */#define _PR_IDLE_THREAD 0x200 /* this is an idle thread */#define _PR_GCABLE_THREAD 0x400 /* this is a collectable thread */#define _PR_BOUND_THREAD 0x800 /* a bound thread */#define _PR_INTERRUPT_BLOCKED 0x1000 /* interrupts blocked *//* PRThread.state */#define _PR_UNBORN 0#define _PR_RUNNABLE 1#define _PR_RUNNING 2#define _PR_LOCK_WAIT 3#define _PR_COND_WAIT 4#define _PR_JOIN_WAIT 5#define _PR_IO_WAIT 6#define _PR_SUSPENDED 7#define _PR_DEAD_STATE 8 /* for debugging *//* PRThreadStack.flags */#define _PR_STACK_VM 0x1 /* using vm instead of malloc */#define _PR_STACK_MAPPED 0x2 /* vm is mapped */#define _PR_STACK_PRIMORDIAL 0x4 /* stack for primordial thread *//* ** If the default stcksize from the client is zero, we need to pick a machine** dependent value. This is only for standard user threads. For custom threads,** 0 has a special meaning.** Adjust stackSize. Round up to a page boundary.*/#ifndef _MD_MINIMUM_STACK_SIZE#define _MD_MINIMUM_STACK_SIZE 0#endif#if (!defined(HAVE_CUSTOM_USER_THREADS))#define _PR_ADJUST_STACKSIZE(stackSize) \ PR_BEGIN_MACRO \ if (stackSize == 0) \ stackSize = _MD_DEFAULT_STACK_SIZE; \ if (stackSize < _MD_MINIMUM_STACK_SIZE) \ stackSize = _MD_MINIMUM_STACK_SIZE; \ stackSize = (stackSize + (1 << _pr_pageShift) - 1) >> _pr_pageShift; \ stackSize <<= _pr_pageShift; \ PR_END_MACRO#else#define _PR_ADJUST_STACKSIZE(stackSize)#endif#ifdef GC_LEAK_DETECTOR/* All threads are GCable. */#define _PR_IS_GCABLE_THREAD(thr) 1#else#define _PR_IS_GCABLE_THREAD(thr) ((thr)->flags & _PR_GCABLE_THREAD)#endif /* GC_LEAK_DETECTOR */#define _PR_PENDING_INTERRUPT(thr) \ (!((thr)->flags & _PR_INTERRUPT_BLOCKED) && ((thr)->flags & _PR_INTERRUPT))#define _PR_THREAD_BLOCK_INTERRUPT(thr) \ (thr->flags |= _PR_INTERRUPT_BLOCKED)#define _PR_THREAD_UNBLOCK_INTERRUPT(thr) \ (thr->flags &= ~_PR_INTERRUPT_BLOCKED)#define _PR_THREAD_PTR(_qp) \ ((PRThread*) ((char*) (_qp) - offsetof(PRThread,links)))#define _PR_ACTIVE_THREAD_PTR(_qp) \ ((PRThread*) ((char*) (_qp) - offsetof(PRThread,active)))#define _PR_THREAD_CONDQ_PTR(_qp) \ ((PRThread*) ((char*) (_qp) - offsetof(PRThread,waitQLinks)))#define _PR_THREAD_MD_TO_PTR(_md) \ ((PRThread*) ((char*) (_md) - offsetof(PRThread,md)))#define _PR_THREAD_STACK_TO_PTR(_stack) \ ((PRThread*) (_stack->thr))extern PRCList _pr_active_local_threadQ;extern PRCList _pr_active_global_threadQ;extern PRCList _pr_cpuQ;extern _MDLock _pr_cpuLock;extern PRInt32 _pr_md_idle_cpus;#define _PR_ACTIVE_LOCAL_THREADQ() _pr_active_local_threadQ#define _PR_ACTIVE_GLOBAL_THREADQ() _pr_active_global_threadQ#define _PR_CPUQ() _pr_cpuQ#define _PR_RUNQ(_cpu) ((_cpu)->queue->runQ)#define _PR_RUNQREADYMASK(_cpu) ((_cpu)->queue->runQReadyMask)#define _PR_SLEEPQ(_cpu) ((_cpu)->queue->sleepQ)#define _PR_SLEEPQMAX(_cpu) ((_cpu)->queue->sleepQmax)#define _PR_PAUSEQ(_cpu) ((_cpu)->queue->pauseQ)#define _PR_SUSPENDQ(_cpu) ((_cpu)->queue->suspendQ)#define _PR_WAITINGTOJOINQ(_cpu) ((_cpu)->queue->waitingToJoinQ)extern PRUint32 _pr_recycleThreads; /* Flag for behavior on thread cleanup */extern PRLock *_pr_deadQLock;extern PRUint32 _pr_numNativeDead;extern PRUint32 _pr_numUserDead;extern PRCList _pr_deadNativeQ;extern PRCList _pr_deadUserQ;#define _PR_DEADNATIVEQ _pr_deadNativeQ#define _PR_DEADUSERQ _pr_deadUserQ#define _PR_DEADQ_LOCK PR_Lock(_pr_deadQLock);#define _PR_DEADQ_UNLOCK PR_Unlock(_pr_deadQLock);#define _PR_INC_DEADNATIVE (_pr_numNativeDead++)#define _PR_DEC_DEADNATIVE (_pr_numNativeDead--)#define _PR_NUM_DEADNATIVE (_pr_numNativeDead)#define _PR_INC_DEADUSER (_pr_numUserDead++)#define _PR_DEC_DEADUSER (_pr_numUserDead--)#define _PR_NUM_DEADUSER (_pr_numUserDead)extern PRUint32 _pr_utid;extern struct _PRCPU *_pr_primordialCPU;extern PRLock *_pr_activeLock; /* lock for userActive and systemActive */extern PRInt32 _pr_userActive; /* number of active user threads */extern PRInt32 _pr_systemActive; /* number of active system threads */extern PRInt32 _pr_primordialExitCount; /* number of user threads left * before the primordial thread * can exit. */extern PRCondVar *_pr_primordialExitCVar; /* the condition variable for * notifying the primordial thread * when all other user threads * have terminated. */extern PRUintn _pr_maxPTDs;extern PRLock *_pr_terminationCVLock;/************************************************************************** Internal routines either called by PR itself or from machine-dependent ** code. **************************************************************************/extern void _PR_ClockInterrupt(void);extern void _PR_Schedule(void);extern void _PR_SetThreadPriority( PRThread* thread, PRThreadPriority priority);/************************************************************************* FUNCTION: _PR_NewSegment()** DESCRIPTION:** Allocate a memory segment. The "size" value is rounded up to the** native system page size and a page aligned portion of memory is** returned. This memory is not part of the malloc heap. If "vaddr" is** not NULL then PR tries to allocate the segment at the desired virtual** address.** INPUTS: size: size of the desired memory segment** vaddr: address at which the newly aquired segment is to be** mapped into memory.** OUTPUTS: a memory segment is allocated, a PRSegment is allocated** RETURN: pointer to PRSegment***********************************************************************/extern PRSegment* _PR_NewSegment(PRUint32 size, void *vaddr);/************************************************************************* FUNCTION: _PR_DestroySegment()** DESCRIPTION:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -