summaryrefslogtreecommitdiffstats
path: root/nsprpub/pr/src/threads
diff options
context:
space:
mode:
Diffstat (limited to 'nsprpub/pr/src/threads')
-rw-r--r--nsprpub/pr/src/threads/combined/prucpu.c83
-rw-r--r--nsprpub/pr/src/threads/combined/prucv.c256
-rw-r--r--nsprpub/pr/src/threads/combined/prulock.c201
-rw-r--r--nsprpub/pr/src/threads/combined/prustack.c133
-rw-r--r--nsprpub/pr/src/threads/combined/pruthr.c765
-rw-r--r--nsprpub/pr/src/threads/prcmon.c56
-rw-r--r--nsprpub/pr/src/threads/prcthr.c199
-rw-r--r--nsprpub/pr/src/threads/prdump.c40
-rw-r--r--nsprpub/pr/src/threads/prmon.c37
-rw-r--r--nsprpub/pr/src/threads/prrwlock.c559
-rw-r--r--nsprpub/pr/src/threads/prsem.c89
-rw-r--r--nsprpub/pr/src/threads/prtpd.c42
12 files changed, 1326 insertions, 1134 deletions
diff --git a/nsprpub/pr/src/threads/combined/prucpu.c b/nsprpub/pr/src/threads/combined/prucpu.c
index 3913dc8de..25ffcce86 100644
--- a/nsprpub/pr/src/threads/combined/prucpu.c
+++ b/nsprpub/pr/src/threads/combined/prucpu.c
@@ -41,8 +41,9 @@ void _PR_InitCPUs()
{
PRThread *me = _PR_MD_CURRENT_THREAD();
- if (_native_threads_only)
+ if (_native_threads_only) {
return;
+ }
_pr_cpuID = 0;
_MD_NEW_LOCK( &_pr_cpuLock);
@@ -119,13 +120,14 @@ static _PRCPUQueue *_PR_CreateCPUQueue(void)
PRInt32 index;
_PRCPUQueue *cpuQueue;
cpuQueue = PR_NEWZAP(_PRCPUQueue);
-
+
_MD_NEW_LOCK( &cpuQueue->runQLock );
_MD_NEW_LOCK( &cpuQueue->sleepQLock );
_MD_NEW_LOCK( &cpuQueue->miscQLock );
- for (index = 0; index < PR_ARRAY_SIZE(cpuQueue->runQ); index++)
+ for (index = 0; index < PR_ARRAY_SIZE(cpuQueue->runQ); index++) {
PR_INIT_CLIST( &(cpuQueue->runQ[index]) );
+ }
PR_INIT_CLIST( &(cpuQueue->sleepQ) );
PR_INIT_CLIST( &(cpuQueue->pauseQ) );
PR_INIT_CLIST( &(cpuQueue->suspendQ) );
@@ -191,7 +193,7 @@ static PRStatus _PR_StartCPU(_PRCPU *cpu, PRThread *thread)
cpu->last_clock = PR_IntervalNow();
/* Before we create any threads on this CPU we have to
- * set the current CPU
+ * set the current CPU
*/
_PR_MD_SET_CURRENT_CPU(cpu);
_PR_MD_INIT_RUNNING_CPU(cpu);
@@ -210,15 +212,16 @@ static PRStatus _PR_StartCPU(_PRCPU *cpu, PRThread *thread)
/* didn't clean up CPU queue XXXMB */
PR_DELETE(cpu);
return PR_FAILURE;
- }
+ }
PR_ASSERT(cpu->idle_thread->cpu == cpu);
cpu->idle_thread->no_sched = 0;
cpu->thread = thread;
- if (_pr_cpu_affinity_mask)
+ if (_pr_cpu_affinity_mask) {
PR_SetThreadAffinityMask(thread, _pr_cpu_affinity_mask);
+ }
/* Created and started a new CPU */
_PR_CPU_LIST_LOCK();
@@ -273,8 +276,10 @@ static void _PR_RunCPU(void *arg)
while(1) {
PRInt32 is;
- if (!_PR_IS_NATIVE_THREAD(me)) _PR_INTSOFF(is);
- _PR_MD_START_INTERRUPTS();
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
+ _PR_MD_START_INTERRUPTS();
_PR_MD_SWITCH_CONTEXT(me);
}
}
@@ -289,13 +294,18 @@ static void PR_CALLBACK _PR_CPU_Idle(void *_cpu)
me->cpu = cpu;
cpu->idle_thread = me;
- if (_MD_LAST_THREAD())
+ if (_MD_LAST_THREAD()) {
_MD_LAST_THREAD()->no_sched = 0;
- if (!_PR_IS_NATIVE_THREAD(me)) _PR_MD_SET_INTSOFF(0);
+ }
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_MD_SET_INTSOFF(0);
+ }
while(1) {
PRInt32 is;
PRIntervalTime timeout;
- if (!_PR_IS_NATIVE_THREAD(me)) _PR_INTSOFF(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_RUNQ_LOCK(cpu);
#if !defined(_PR_LOCAL_THREADS_ONLY) && !defined(_PR_GLOBAL_THREADS_ONLY)
@@ -345,14 +355,16 @@ static void PR_CALLBACK _PR_CPU_Idle(void *_cpu)
#endif /* _PR_HAVE_ATOMIC_OPS */
#endif
- _PR_ClockInterrupt();
+ _PR_ClockInterrupt();
- /* Now schedule any thread that is on the runq
- * INTS must be OFF when calling PR_Schedule()
- */
- me->state = _PR_RUNNABLE;
- _PR_MD_SWITCH_CONTEXT(me);
- if (!_PR_IS_NATIVE_THREAD(me)) _PR_FAST_INTSON(is);
+ /* Now schedule any thread that is on the runq
+ * INTS must be OFF when calling PR_Schedule()
+ */
+ me->state = _PR_RUNNABLE;
+ _PR_MD_SWITCH_CONTEXT(me);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
}
}
#endif /* _PR_GLOBAL_THREADS_ONLY */
@@ -370,36 +382,43 @@ PR_IMPLEMENT(void) PR_SetConcurrency(PRUintn numCPUs)
PRThread *thr;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+
+ if (_native_threads_only) {
+ return;
+ }
- if (_native_threads_only)
- return;
-
_PR_CPU_LIST_LOCK();
if (_pr_numCPU < numCPUs) {
newCPU = numCPUs - _pr_numCPU;
_pr_numCPU = numCPUs;
- } else newCPU = 0;
+ } else {
+ newCPU = 0;
+ }
_PR_CPU_LIST_UNLOCK();
for (; newCPU; newCPU--) {
cpu = _PR_CreateCPU();
thr = _PR_CreateThread(PR_SYSTEM_THREAD,
- _PR_RunCPU,
- cpu,
- PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0,
- _PR_IDLE_THREAD);
+ _PR_RunCPU,
+ cpu,
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0,
+ _PR_IDLE_THREAD);
}
#endif
}
PR_IMPLEMENT(_PRCPU *) _PR_GetPrimordialCPU(void)
{
- if (_pr_primordialCPU)
+ if (_pr_primordialCPU) {
return _pr_primordialCPU;
- else
+ }
+ else {
return _PR_MD_CURRENT_CPU();
+ }
}
diff --git a/nsprpub/pr/src/threads/combined/prucv.c b/nsprpub/pr/src/threads/combined/prucv.c
index d0bf4c422..801d3d2fd 100644
--- a/nsprpub/pr/src/threads/combined/prucv.c
+++ b/nsprpub/pr/src/threads/combined/prucv.c
@@ -10,10 +10,10 @@
#if defined(WIN95)
/*
-** Some local variables report warnings on Win95 because the code paths
+** Some local variables report warnings on Win95 because the code paths
** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
** The pragma suppresses the warning.
-**
+**
*/
#pragma warning(disable : 4101)
#endif
@@ -39,24 +39,25 @@ PRBool _PR_NotifyThread (PRThread *thread, PRThread *me)
/* The notify and timeout can collide; in which case both may
* attempt to delete from the sleepQ; only let one do it.
*/
- if (thread->flags & (_PR_ON_SLEEPQ|_PR_ON_PAUSEQ))
+ if (thread->flags & (_PR_ON_SLEEPQ|_PR_ON_PAUSEQ)) {
_PR_DEL_SLEEPQ(thread, PR_TRUE);
+ }
_PR_SLEEPQ_UNLOCK(thread->cpu);
- if (thread->flags & _PR_SUSPENDING) {
- /*
- * set thread state to SUSPENDED; a Resume operation
- * on the thread will move it to the runQ
- */
- thread->state = _PR_SUSPENDED;
- _PR_MISCQ_LOCK(thread->cpu);
- _PR_ADD_SUSPENDQ(thread, thread->cpu);
- _PR_MISCQ_UNLOCK(thread->cpu);
- _PR_THREAD_UNLOCK(thread);
- } else {
- /* Make thread runnable */
- thread->state = _PR_RUNNABLE;
- _PR_THREAD_UNLOCK(thread);
+ if (thread->flags & _PR_SUSPENDING) {
+ /*
+ * set thread state to SUSPENDED; a Resume operation
+ * on the thread will move it to the runQ
+ */
+ thread->state = _PR_SUSPENDED;
+ _PR_MISCQ_LOCK(thread->cpu);
+ _PR_ADD_SUSPENDQ(thread, thread->cpu);
+ _PR_MISCQ_UNLOCK(thread->cpu);
+ _PR_THREAD_UNLOCK(thread);
+ } else {
+ /* Make thread runnable */
+ thread->state = _PR_RUNNABLE;
+ _PR_THREAD_UNLOCK(thread);
_PR_AddThreadToRunQ(me, thread);
_PR_MD_WAKEUP_WAITER(thread);
@@ -72,29 +73,30 @@ PRBool _PR_NotifyThread (PRThread *thread, PRThread *me)
if (thread->wait.cvar) {
thread->wait.cvar = NULL;
- if (thread->flags & _PR_SUSPENDING) {
- /*
- * set thread state to SUSPENDED; a Resume operation
- * on the thread will enable the thread to run
- */
- thread->state = _PR_SUSPENDED;
- } else
- thread->state = _PR_RUNNING;
+ if (thread->flags & _PR_SUSPENDING) {
+ /*
+ * set thread state to SUSPENDED; a Resume operation
+ * on the thread will enable the thread to run
+ */
+ thread->state = _PR_SUSPENDED;
+ } else {
+ thread->state = _PR_RUNNING;
+ }
_PR_THREAD_UNLOCK(thread);
_PR_MD_WAKEUP_WAITER(thread);
rv = PR_TRUE;
} else {
_PR_THREAD_UNLOCK(thread);
rv = PR_FALSE;
- }
- }
+ }
+ }
return rv;
}
/*
* Notify thread waiting on cvar; called when thread is interrupted
- * The thread lock is held on entry and released before return
+ * The thread lock is held on entry and released before return
*/
void _PR_NotifyLockedThread (PRThread *thread)
{
@@ -102,8 +104,9 @@ void _PR_NotifyLockedThread (PRThread *thread)
PRCondVar *cvar;
PRThreadPriority pri;
- if ( !_PR_IS_NATIVE_THREAD(me))
- PR_ASSERT(_PR_MD_GET_INTSOFF() != 0);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ PR_ASSERT(_PR_MD_GET_INTSOFF() != 0);
+ }
cvar = thread->wait.cvar;
thread->wait.cvar = NULL;
@@ -113,36 +116,38 @@ void _PR_NotifyLockedThread (PRThread *thread)
_PR_THREAD_LOCK(thread);
if (!_PR_IS_NATIVE_THREAD(thread)) {
- _PR_SLEEPQ_LOCK(thread->cpu);
- /* The notify and timeout can collide; in which case both may
- * attempt to delete from the sleepQ; only let one do it.
- */
- if (thread->flags & (_PR_ON_SLEEPQ|_PR_ON_PAUSEQ))
- _PR_DEL_SLEEPQ(thread, PR_TRUE);
- _PR_SLEEPQ_UNLOCK(thread->cpu);
+ _PR_SLEEPQ_LOCK(thread->cpu);
+ /* The notify and timeout can collide; in which case both may
+ * attempt to delete from the sleepQ; only let one do it.
+ */
+ if (thread->flags & (_PR_ON_SLEEPQ|_PR_ON_PAUSEQ)) {
+ _PR_DEL_SLEEPQ(thread, PR_TRUE);
+ }
+ _PR_SLEEPQ_UNLOCK(thread->cpu);
- /* Make thread runnable */
- pri = thread->priority;
- thread->state = _PR_RUNNABLE;
+ /* Make thread runnable */
+ pri = thread->priority;
+ thread->state = _PR_RUNNABLE;
- PR_ASSERT(!(thread->flags & _PR_IDLE_THREAD));
+ PR_ASSERT(!(thread->flags & _PR_IDLE_THREAD));
- _PR_AddThreadToRunQ(me, thread);
- _PR_THREAD_UNLOCK(thread);
+ _PR_AddThreadToRunQ(me, thread);
+ _PR_THREAD_UNLOCK(thread);
- _PR_MD_WAKEUP_WAITER(thread);
+ _PR_MD_WAKEUP_WAITER(thread);
} else {
- if (thread->flags & _PR_SUSPENDING) {
- /*
- * set thread state to SUSPENDED; a Resume operation
- * on the thread will enable the thread to run
- */
- thread->state = _PR_SUSPENDED;
- } else
- thread->state = _PR_RUNNING;
- _PR_THREAD_UNLOCK(thread);
- _PR_MD_WAKEUP_WAITER(thread);
- }
+ if (thread->flags & _PR_SUSPENDING) {
+ /*
+ * set thread state to SUSPENDED; a Resume operation
+ * on the thread will enable the thread to run
+ */
+ thread->state = _PR_SUSPENDED;
+ } else {
+ thread->state = _PR_RUNNING;
+ }
+ _PR_THREAD_UNLOCK(thread);
+ _PR_MD_WAKEUP_WAITER(thread);
+ }
_PR_CVAR_UNLOCK(cvar);
return;
@@ -181,8 +186,9 @@ PRStatus _PR_WaitCondVar(
return PR_SUCCESS;
#else /* _PR_GLOBAL_THREADS_ONLY */
- if ( !_PR_IS_NATIVE_THREAD(thread))
- _PR_INTSOFF(is);
+ if ( !_PR_IS_NATIVE_THREAD(thread)) {
+ _PR_INTSOFF(is);
+ }
_PR_CVAR_LOCK(cvar);
_PR_THREAD_LOCK(thread);
@@ -190,10 +196,11 @@ PRStatus _PR_WaitCondVar(
if (_PR_PENDING_INTERRUPT(thread)) {
PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
thread->flags &= ~_PR_INTERRUPT;
- _PR_CVAR_UNLOCK(cvar);
- _PR_THREAD_UNLOCK(thread);
- if ( !_PR_IS_NATIVE_THREAD(thread))
- _PR_INTSON(is);
+ _PR_CVAR_UNLOCK(cvar);
+ _PR_THREAD_UNLOCK(thread);
+ if ( !_PR_IS_NATIVE_THREAD(thread)) {
+ _PR_INTSON(is);
+ }
return PR_FAILURE;
}
@@ -216,15 +223,15 @@ PRStatus _PR_WaitCondVar(
}
_PR_CVAR_UNLOCK(cvar);
_PR_THREAD_UNLOCK(thread);
-
- /*
- ** Release lock protecting the condition variable and thereby giving time
+
+ /*
+ ** Release lock protecting the condition variable and thereby giving time
** to the next thread which can potentially notify on the condition variable
*/
PR_Unlock(lock);
PR_LOG(_pr_cvar_lm, PR_LOG_MIN,
- ("PR_Wait: cvar=%p waiting for %d", cvar, timeout));
+ ("PR_Wait: cvar=%p waiting for %d", cvar, timeout));
rv = _PR_MD_WAIT(thread, timeout);
@@ -233,10 +240,11 @@ PRStatus _PR_WaitCondVar(
_PR_CVAR_UNLOCK(cvar);
PR_LOG(_pr_cvar_lm, PR_LOG_MIN,
- ("PR_Wait: cvar=%p done waiting", cvar));
+ ("PR_Wait: cvar=%p done waiting", cvar));
- if ( !_PR_IS_NATIVE_THREAD(thread))
- _PR_INTSON(is);
+ if ( !_PR_IS_NATIVE_THREAD(thread)) {
+ _PR_INTSON(is);
+ }
/* Acquire lock again that we had just relinquished */
PR_Lock(lock);
@@ -260,8 +268,9 @@ void _PR_NotifyCondVar(PRCondVar *cvar, PRThread *me)
PRCList *q;
PRIntn is;
- if ( !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
PR_ASSERT(_PR_IS_NATIVE_THREAD(me) || _PR_MD_GET_INTSOFF() != 0);
_PR_CVAR_LOCK(cvar);
@@ -269,15 +278,17 @@ void _PR_NotifyCondVar(PRCondVar *cvar, PRThread *me)
while (q != &cvar->condQ) {
PR_LOG(_pr_cvar_lm, PR_LOG_MIN, ("_PR_NotifyCondVar: cvar=%p", cvar));
if (_PR_THREAD_CONDQ_PTR(q)->wait.cvar) {
- if (_PR_NotifyThread(_PR_THREAD_CONDQ_PTR(q), me) == PR_TRUE)
+ if (_PR_NotifyThread(_PR_THREAD_CONDQ_PTR(q), me) == PR_TRUE) {
break;
+ }
}
q = q->next;
}
_PR_CVAR_UNLOCK(cvar);
- if ( !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSON(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
#endif /* _PR_GLOBAL_THREADS_ONLY */
}
@@ -290,10 +301,10 @@ PRUint32 _PR_CondVarToString(PRCondVar *cvar, char *buf, PRUint32 buflen)
PRUint32 nb;
if (cvar->lock->owner) {
- nb = PR_snprintf(buf, buflen, "[%p] owner=%ld[%p]",
- cvar, cvar->lock->owner->id, cvar->lock->owner);
+ nb = PR_snprintf(buf, buflen, "[%p] owner=%ld[%p]",
+ cvar, cvar->lock->owner->id, cvar->lock->owner);
} else {
- nb = PR_snprintf(buf, buflen, "[%p]", cvar);
+ nb = PR_snprintf(buf, buflen, "[%p]", cvar);
}
return nb;
}
@@ -307,7 +318,7 @@ void _PR_ClockInterrupt(void)
PRThread *thread, *me = _PR_MD_CURRENT_THREAD();
_PRCPU *cpu = me->cpu;
PRIntervalTime elapsed, now;
-
+
PR_ASSERT(_PR_MD_GET_INTSOFF() != 0);
/* Figure out how much time elapsed since the last clock tick */
now = PR_IntervalNow();
@@ -315,7 +326,7 @@ void _PR_ClockInterrupt(void)
cpu->last_clock = now;
PR_LOG(_pr_clock_lm, PR_LOG_MAX,
- ("ExpireWaits: elapsed=%lld usec", elapsed));
+ ("ExpireWaits: elapsed=%lld usec", elapsed));
while(1) {
_PR_SLEEPQ_LOCK(cpu);
@@ -370,8 +381,8 @@ void _PR_ClockInterrupt(void)
/* Notify the thread waiting on the condition variable */
if (thread->flags & _PR_SUSPENDING) {
- PR_ASSERT((thread->state == _PR_IO_WAIT) ||
- (thread->state == _PR_COND_WAIT));
+ PR_ASSERT((thread->state == _PR_IO_WAIT) ||
+ (thread->state == _PR_COND_WAIT));
/*
** Thread is suspended and its condition timeout
** expired. Transfer thread from sleepQ to suspendQ.
@@ -398,8 +409,9 @@ void _PR_ClockInterrupt(void)
_PR_ADD_RUNQ(thread, cpu, pri);
_PR_RUNQ_UNLOCK(cpu);
- if (pri > me->priority)
+ if (pri > me->priority) {
_PR_SET_RESCHED_FLAG();
+ }
thread->wait.cvar = NULL;
@@ -411,14 +423,14 @@ void _PR_ClockInterrupt(void)
thread->io_suspended = PR_TRUE;
#ifdef WINNT
- /*
- * For NT, record the cpu on which I/O was issued
- * I/O cancellation is done on the same cpu
- */
+ /*
+ * For NT, record the cpu on which I/O was issued
+ * I/O cancellation is done on the same cpu
+ */
thread->md.thr_bound_cpu = cpu;
#endif
- PR_ASSERT(!(thread->flags & _PR_IDLE_THREAD));
+ PR_ASSERT(!(thread->flags & _PR_IDLE_THREAD));
PR_ASSERT(thread->cpu == cpu);
thread->state = _PR_RUNNABLE;
_PR_RUNQ_LOCK(cpu);
@@ -434,7 +446,7 @@ void _PR_ClockInterrupt(void)
/*
** Create a new condition variable.
-** "lock" is the lock to use with the condition variable.
+** "lock" is the lock to use with the condition variable.
**
** Condition variables are synchronization objects that threads can use
** to wait for some condition to occur.
@@ -518,11 +530,13 @@ PR_IMPLEMENT(PRStatus) PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout)
{
PRThread *me = _PR_MD_CURRENT_THREAD();
- PR_ASSERT(cvar->lock->owner == me);
- PR_ASSERT(me != suspendAllThread);
- if (cvar->lock->owner != me) return PR_FAILURE;
+ PR_ASSERT(cvar->lock->owner == me);
+ PR_ASSERT(me != suspendAllThread);
+ if (cvar->lock->owner != me) {
+ return PR_FAILURE;
+ }
- return _PR_WaitCondVar(me, cvar, cvar->lock, timeout);
+ return _PR_WaitCondVar(me, cvar, cvar->lock, timeout);
}
/*
@@ -536,7 +550,9 @@ PR_IMPLEMENT(PRStatus) PR_NotifyCondVar(PRCondVar *cvar)
PR_ASSERT(cvar->lock->owner == me);
PR_ASSERT(me != suspendAllThread);
- if (cvar->lock->owner != me) return PR_FAILURE;
+ if (cvar->lock->owner != me) {
+ return PR_FAILURE;
+ }
_PR_NotifyCondVar(cvar, me);
return PR_SUCCESS;
@@ -554,24 +570,28 @@ PR_IMPLEMENT(PRStatus) PR_NotifyAllCondVar(PRCondVar *cvar)
PRThread *me = _PR_MD_CURRENT_THREAD();
PR_ASSERT(cvar->lock->owner == me);
- if (cvar->lock->owner != me) return PR_FAILURE;
+ if (cvar->lock->owner != me) {
+ return PR_FAILURE;
+ }
#ifdef _PR_GLOBAL_THREADS_ONLY
_PR_MD_NOTIFYALL_CV(&cvar->md, &cvar->lock->ilock);
return PR_SUCCESS;
#else /* _PR_GLOBAL_THREADS_ONLY */
- if ( !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_CVAR_LOCK(cvar);
q = cvar->condQ.next;
while (q != &cvar->condQ) {
- PR_LOG(_pr_cvar_lm, PR_LOG_MIN, ("PR_NotifyAll: cvar=%p", cvar));
- _PR_NotifyThread(_PR_THREAD_CONDQ_PTR(q), me);
- q = q->next;
+ PR_LOG(_pr_cvar_lm, PR_LOG_MIN, ("PR_NotifyAll: cvar=%p", cvar));
+ _PR_NotifyThread(_PR_THREAD_CONDQ_PTR(q), me);
+ q = q->next;
}
_PR_CVAR_UNLOCK(cvar);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSON(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
return PR_SUCCESS;
#endif /* _PR_GLOBAL_THREADS_ONLY */
@@ -592,13 +612,13 @@ PR_IMPLEMENT(PRCondVar*) PRP_NewNakedCondVar(void)
{
if (_PR_MD_NEW_LOCK(&(cvar->ilock)) == PR_FAILURE)
{
- PR_DELETE(cvar); cvar = NULL;
- }
- else
- {
- PR_INIT_CLIST(&cvar->condQ);
+ PR_DELETE(cvar); cvar = NULL;
+ }
+ else
+ {
+ PR_INIT_CLIST(&cvar->condQ);
cvar->lock = _PR_NAKED_CV_LOCK;
- }
+ }
}
return cvar;
@@ -610,16 +630,16 @@ PR_IMPLEMENT(void) PRP_DestroyNakedCondVar(PRCondVar *cvar)
PR_ASSERT(_PR_NAKED_CV_LOCK == cvar->lock);
_PR_MD_FREE_LOCK(&(cvar->ilock));
-
+
PR_DELETE(cvar);
}
PR_IMPLEMENT(PRStatus) PRP_NakedWait(
- PRCondVar *cvar, PRLock *lock, PRIntervalTime timeout)
+ PRCondVar *cvar, PRLock *lock, PRIntervalTime timeout)
{
PRThread *me = _PR_MD_CURRENT_THREAD();
PR_ASSERT(_PR_NAKED_CV_LOCK == cvar->lock);
- return _PR_WaitCondVar(me, cvar, lock, timeout);
+ return _PR_WaitCondVar(me, cvar, lock, timeout);
} /* PRP_NakedWait */
PR_IMPLEMENT(PRStatus) PRP_NakedNotify(PRCondVar *cvar)
@@ -639,16 +659,20 @@ PR_IMPLEMENT(PRStatus) PRP_NakedBroadcast(PRCondVar *cvar)
PRThread *me = _PR_MD_CURRENT_THREAD();
PR_ASSERT(_PR_NAKED_CV_LOCK == cvar->lock);
- if ( !_PR_IS_NATIVE_THREAD(me)) _PR_INTSOFF(is);
- _PR_MD_LOCK( &(cvar->ilock) );
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
+ _PR_MD_LOCK( &(cvar->ilock) );
q = cvar->condQ.next;
while (q != &cvar->condQ) {
- PR_LOG(_pr_cvar_lm, PR_LOG_MIN, ("PR_NotifyAll: cvar=%p", cvar));
- _PR_NotifyThread(_PR_THREAD_CONDQ_PTR(q), me);
- q = q->next;
+ PR_LOG(_pr_cvar_lm, PR_LOG_MIN, ("PR_NotifyAll: cvar=%p", cvar));
+ _PR_NotifyThread(_PR_THREAD_CONDQ_PTR(q), me);
+ q = q->next;
+ }
+ _PR_MD_UNLOCK( &(cvar->ilock) );
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
}
- _PR_MD_UNLOCK( &(cvar->ilock) );
- if (!_PR_IS_NATIVE_THREAD(me)) _PR_INTSON(is);
return PR_SUCCESS;
} /* PRP_NakedBroadcast */
diff --git a/nsprpub/pr/src/threads/combined/prulock.c b/nsprpub/pr/src/threads/combined/prulock.c
index 8b2f41eec..69c27d149 100644
--- a/nsprpub/pr/src/threads/combined/prulock.c
+++ b/nsprpub/pr/src/threads/combined/prulock.c
@@ -7,10 +7,10 @@
#if defined(WIN95)
/*
-** Some local variables report warnings on Win95 because the code paths
+** Some local variables report warnings on Win95 because the code paths
** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
** The pragma suppresses the warning.
-**
+**
*/
#pragma warning(disable : 4101)
#endif
@@ -18,7 +18,7 @@
void _PR_InitLocks(void)
{
- _PR_MD_INIT_LOCKS();
+ _PR_MD_INIT_LOCKS();
}
/*
@@ -33,7 +33,7 @@ void _PR_IntsOn(_PRCPU *cpu)
PR_ASSERT(cpu); /* Global threads don't have CPUs */
PR_ASSERT(_PR_MD_GET_INTSOFF() > 0);
- me = _PR_MD_CURRENT_THREAD();
+ me = _PR_MD_CURRENT_THREAD();
PR_ASSERT(!(me->flags & _PR_IDLE_THREAD));
/*
@@ -69,15 +69,15 @@ void _PR_IntsOn(_PRCPU *cpu)
if (cpu->u.missed[3] != 0) {
_PRCPU *cpu;
- _PR_THREAD_LOCK(me);
+ _PR_THREAD_LOCK(me);
me->state = _PR_RUNNABLE;
pri = me->priority;
cpu = me->cpu;
- _PR_RUNQ_LOCK(cpu);
+ _PR_RUNQ_LOCK(cpu);
_PR_ADD_RUNQ(me, cpu, pri);
- _PR_RUNQ_UNLOCK(cpu);
- _PR_THREAD_UNLOCK(me);
+ _PR_RUNQ_UNLOCK(cpu);
+ _PR_THREAD_UNLOCK(me);
_PR_MD_SWITCH_CONTEXT(me);
}
}
@@ -99,11 +99,11 @@ void _PR_UnblockLockWaiter(PRLock *lock)
/* Unblock first waiter */
t = _PR_THREAD_CONDQ_PTR(q);
- /*
- ** We are about to change the thread's state to runnable and for local
- ** threads, we are going to assign a cpu to it. So, protect thread's
- ** data structure.
- */
+ /*
+ ** We are about to change the thread's state to runnable and for local
+ ** threads, we are going to assign a cpu to it. So, protect thread's
+ ** data structure.
+ */
_PR_THREAD_LOCK(t);
if (t->flags & _PR_SUSPENDING) {
@@ -113,24 +113,24 @@ void _PR_UnblockLockWaiter(PRLock *lock)
}
/* Found a runnable thread */
- PR_ASSERT(t->state == _PR_LOCK_WAIT);
- PR_ASSERT(t->wait.lock == lock);
+ PR_ASSERT(t->state == _PR_LOCK_WAIT);
+ PR_ASSERT(t->wait.lock == lock);
t->wait.lock = 0;
PR_REMOVE_LINK(&t->waitQLinks); /* take it off lock's waitQ */
- /*
- ** If this is a native thread, nothing else to do except to wake it
- ** up by calling the machine dependent wakeup routine.
- **
- ** If this is a local thread, we need to assign it a cpu and
- ** put the thread on that cpu's run queue. There are two cases to
- ** take care of. If the currently running thread is also a local
- ** thread, we just assign our own cpu to that thread and put it on
- ** the cpu's run queue. If the the currently running thread is a
- ** native thread, we assign the primordial cpu to it (on NT,
- ** MD_WAKEUP handles the cpu assignment).
- */
-
+ /*
+ ** If this is a native thread, nothing else to do except to wake it
+ ** up by calling the machine dependent wakeup routine.
+ **
+ ** If this is a local thread, we need to assign it a cpu and
+ ** put the thread on that cpu's run queue. There are two cases to
+ ** take care of. If the currently running thread is also a local
+ ** thread, we just assign our own cpu to that thread and put it on
+ ** the cpu's run queue. If the the currently running thread is a
+ ** native thread, we assign the primordial cpu to it (on NT,
+ ** MD_WAKEUP handles the cpu assignment).
+ */
+
if ( !_PR_IS_NATIVE_THREAD(t) ) {
t->state = _PR_RUNNABLE;
@@ -156,7 +156,9 @@ PR_IMPLEMENT(PRLock*) PR_NewLock(void)
{
PRLock *lock;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
lock = PR_NEWZAP(PRLock);
if (lock) {
@@ -206,25 +208,26 @@ PR_IMPLEMENT(void) PR_Lock(PRLock *lock)
PRThread *t;
PRCList *q;
- PR_ASSERT(me != suspendAllThread);
+ PR_ASSERT(me != suspendAllThread);
PR_ASSERT(!(me->flags & _PR_IDLE_THREAD));
PR_ASSERT(lock != NULL);
-#ifdef _PR_GLOBAL_THREADS_ONLY
+#ifdef _PR_GLOBAL_THREADS_ONLY
_PR_MD_LOCK(&lock->ilock);
PR_ASSERT(lock->owner == 0);
lock->owner = me;
return;
#else /* _PR_GLOBAL_THREADS_ONLY */
- if (_native_threads_only) {
- _PR_MD_LOCK(&lock->ilock);
- PR_ASSERT(lock->owner == 0);
- lock->owner = me;
- return;
- }
+ if (_native_threads_only) {
+ _PR_MD_LOCK(&lock->ilock);
+ PR_ASSERT(lock->owner == 0);
+ lock->owner = me;
+ return;
+ }
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
PR_ASSERT(_PR_IS_NATIVE_THREAD(me) || _PR_MD_GET_INTSOFF() != 0);
@@ -234,11 +237,12 @@ retry:
/* Just got the lock */
lock->owner = me;
lock->priority = me->priority;
- /* Add the granted lock to this owning thread's lock list */
+ /* Add the granted lock to this owning thread's lock list */
PR_APPEND_LINK(&lock->links, &me->lockList);
_PR_LOCK_UNLOCK(lock);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
return;
}
@@ -258,39 +262,39 @@ retry:
}
#endif
- /*
+ /*
Add this thread to the asked for lock's list of waiting threads. We
add this thread thread in the right priority order so when the unlock
occurs, the thread with the higher priority will get the lock.
*/
q = lock->waitQ.next;
if (q == &lock->waitQ || _PR_THREAD_CONDQ_PTR(q)->priority ==
- _PR_THREAD_CONDQ_PTR(lock->waitQ.prev)->priority) {
- /*
- * If all the threads in the lock waitQ have the same priority,
- * then avoid scanning the list: insert the element at the end.
- */
- q = &lock->waitQ;
+ _PR_THREAD_CONDQ_PTR(lock->waitQ.prev)->priority) {
+ /*
+ * If all the threads in the lock waitQ have the same priority,
+ * then avoid scanning the list: insert the element at the end.
+ */
+ q = &lock->waitQ;
} else {
- /* Sort thread into lock's waitQ at appropriate point */
- /* Now scan the list for where to insert this entry */
- while (q != &lock->waitQ) {
- t = _PR_THREAD_CONDQ_PTR(lock->waitQ.next);
- if (me->priority > t->priority) {
- /* Found a lower priority thread to insert in front of */
- break;
- }
- q = q->next;
- }
- }
+ /* Sort thread into lock's waitQ at appropriate point */
+ /* Now scan the list for where to insert this entry */
+ while (q != &lock->waitQ) {
+ t = _PR_THREAD_CONDQ_PTR(lock->waitQ.next);
+ if (me->priority > t->priority) {
+ /* Found a lower priority thread to insert in front of */
+ break;
+ }
+ q = q->next;
+ }
+ }
PR_INSERT_BEFORE(&me->waitQLinks, q);
- /*
- Now grab the threadLock since we are about to change the state. We have
- to do this since a PR_Suspend or PR_SetThreadPriority type call that takes
- a PRThread* as an argument could be changing the state of this thread from
- a thread running on a different cpu.
- */
+ /*
+ Now grab the threadLock since we are about to change the state. We have
+ to do this since a PR_Suspend or PR_SetThreadPriority type call that takes
+ a PRThread* as an argument could be changing the state of this thread from
+ a thread running on a different cpu.
+ */
_PR_THREAD_LOCK(me);
me->state = _PR_LOCK_WAIT;
@@ -300,7 +304,7 @@ retry:
_PR_LOCK_UNLOCK(lock);
_PR_MD_WAIT(me, PR_INTERVAL_NO_TIMEOUT);
- goto retry;
+ goto retry;
#endif /* _PR_GLOBAL_THREADS_ONLY */
}
@@ -317,29 +321,30 @@ PR_IMPLEMENT(PRStatus) PR_Unlock(PRLock *lock)
PR_ASSERT(lock != NULL);
PR_ASSERT(lock->owner == me);
- PR_ASSERT(me != suspendAllThread);
+ PR_ASSERT(me != suspendAllThread);
PR_ASSERT(!(me->flags & _PR_IDLE_THREAD));
if (lock->owner != me) {
return PR_FAILURE;
}
-#ifdef _PR_GLOBAL_THREADS_ONLY
+#ifdef _PR_GLOBAL_THREADS_ONLY
lock->owner = 0;
_PR_MD_UNLOCK(&lock->ilock);
return PR_SUCCESS;
#else /* _PR_GLOBAL_THREADS_ONLY */
- if (_native_threads_only) {
- lock->owner = 0;
- _PR_MD_UNLOCK(&lock->ilock);
- return PR_SUCCESS;
- }
+ if (_native_threads_only) {
+ lock->owner = 0;
+ _PR_MD_UNLOCK(&lock->ilock);
+ return PR_SUCCESS;
+ }
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_LOCK_LOCK(lock);
- /* Remove the lock from the owning thread's lock list */
+ /* Remove the lock from the owning thread's lock list */
PR_REMOVE_LINK(&lock->links);
pri = lock->priority;
boost = lock->boostPriority;
@@ -365,13 +370,15 @@ PR_IMPLEMENT(PRStatus) PR_Unlock(PRLock *lock)
/* Unblock the first waiting thread */
q = lock->waitQ.next;
- if (q != &lock->waitQ)
+ if (q != &lock->waitQ) {
_PR_UnblockLockWaiter(lock);
+ }
lock->boostPriority = PR_PRIORITY_LOW;
lock->owner = 0;
_PR_LOCK_UNLOCK(lock);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSON(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
return PR_SUCCESS;
#endif /* _PR_GLOBAL_THREADS_ONLY */
}
@@ -397,7 +404,7 @@ PR_IMPLEMENT(PRBool) PR_TestAndLock(PRLock *lock)
PRBool rv = PR_FALSE;
PRIntn is;
-#ifdef _PR_GLOBAL_THREADS_ONLY
+#ifdef _PR_GLOBAL_THREADS_ONLY
is = _PR_MD_TEST_AND_LOCK(&lock->ilock);
if (is == 0) {
lock->owner = me;
@@ -407,32 +414,34 @@ PR_IMPLEMENT(PRBool) PR_TestAndLock(PRLock *lock)
#else /* _PR_GLOBAL_THREADS_ONLY */
#ifndef _PR_LOCAL_THREADS_ONLY
- if (_native_threads_only) {
- is = _PR_MD_TEST_AND_LOCK(&lock->ilock);
- if (is == 0) {
- lock->owner = me;
- return PR_TRUE;
- }
- return PR_FALSE;
- }
+ if (_native_threads_only) {
+ is = _PR_MD_TEST_AND_LOCK(&lock->ilock);
+ if (is == 0) {
+ lock->owner = me;
+ return PR_TRUE;
+ }
+ return PR_FALSE;
+ }
#endif
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_LOCK_LOCK(lock);
if (lock->owner == 0) {
/* Just got the lock */
lock->owner = me;
lock->priority = me->priority;
- /* Add the granted lock to this owning thread's lock list */
+ /* Add the granted lock to this owning thread's lock list */
PR_APPEND_LINK(&lock->links, &me->lockList);
rv = PR_TRUE;
}
_PR_LOCK_UNLOCK(lock);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSON(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
return rv;
#endif /* _PR_GLOBAL_THREADS_ONLY */
}
@@ -443,4 +452,6 @@ PR_IMPLEMENT(PRBool) PR_TestAndLock(PRLock *lock)
/************************************************************************/
/************************************************************************/
PR_IMPLEMENT(PRStatus) PRP_TryLock(PRLock *lock)
- { return (PR_TestAndLock(lock)) ? PR_SUCCESS : PR_FAILURE; }
+{
+ return (PR_TestAndLock(lock)) ? PR_SUCCESS : PR_FAILURE;
+}
diff --git a/nsprpub/pr/src/threads/combined/prustack.c b/nsprpub/pr/src/threads/combined/prustack.c
index 59562bac4..3f5452c48 100644
--- a/nsprpub/pr/src/threads/combined/prustack.c
+++ b/nsprpub/pr/src/threads/combined/prustack.c
@@ -19,7 +19,7 @@ PRBool _pr_debugStacks = PR_FALSE;
#endif
/* How much space to leave between the stacks, at each end */
-#define REDZONE (2 << _pr_pageShift)
+#define REDZONE (2 << _pr_pageShift)
#define _PR_THREAD_STACK_PTR(_qp) \
((PRThreadStack*) ((char*) (_qp) - offsetof(PRThreadStack,links)))
@@ -54,22 +54,23 @@ PRThreadStack *_PR_NewStack(PRUint32 stackSize)
PR_Lock(_pr_stackLock);
qp = _pr_freeStacks.prev;
while ((_pr_numFreeStacks > _pr_maxFreeStacks) && (qp != &_pr_freeStacks)) {
- ts = _PR_THREAD_STACK_PTR(qp);
- thr = _PR_THREAD_STACK_TO_PTR(ts);
- qp = qp->prev;
- /*
- * skip stacks which are still being used
- */
- if (thr->no_sched)
- continue;
- PR_REMOVE_LINK(&ts->links);
-
- /* Give platform OS to clear out the stack for debugging */
- _PR_MD_CLEAR_STACK(ts);
-
- _pr_numFreeStacks--;
- _PR_DestroySegment(ts->seg);
- PR_DELETE(ts);
+ ts = _PR_THREAD_STACK_PTR(qp);
+ thr = _PR_THREAD_STACK_TO_PTR(ts);
+ qp = qp->prev;
+ /*
+ * skip stacks which are still being used
+ */
+ if (thr->no_sched) {
+ continue;
+ }
+ PR_REMOVE_LINK(&ts->links);
+
+ /* Give platform OS to clear out the stack for debugging */
+ _PR_MD_CLEAR_STACK(ts);
+
+ _pr_numFreeStacks--;
+ _PR_DestroySegment(ts->seg);
+ PR_DELETE(ts);
}
/*
@@ -79,51 +80,51 @@ PRThreadStack *_PR_NewStack(PRUint32 stackSize)
qp = _pr_freeStacks.next;
ts = 0;
while (qp != &_pr_freeStacks) {
- ts = _PR_THREAD_STACK_PTR(qp);
- thr = _PR_THREAD_STACK_TO_PTR(ts);
- qp = qp->next;
- /*
- * skip stacks which are still being used
- */
- if ((!(thr->no_sched)) && ((ts->allocSize - 2*REDZONE) >= stackSize)) {
- /*
- ** Found a stack that is not in use and is big enough. Change
- ** stackSize to fit it.
- */
- stackSize = ts->allocSize - 2*REDZONE;
- PR_REMOVE_LINK(&ts->links);
- _pr_numFreeStacks--;
- ts->links.next = 0;
- ts->links.prev = 0;
- PR_Unlock(_pr_stackLock);
- goto done;
- }
- ts = 0;
+ ts = _PR_THREAD_STACK_PTR(qp);
+ thr = _PR_THREAD_STACK_TO_PTR(ts);
+ qp = qp->next;
+ /*
+ * skip stacks which are still being used
+ */
+ if ((!(thr->no_sched)) && ((ts->allocSize - 2*REDZONE) >= stackSize)) {
+ /*
+ ** Found a stack that is not in use and is big enough. Change
+ ** stackSize to fit it.
+ */
+ stackSize = ts->allocSize - 2*REDZONE;
+ PR_REMOVE_LINK(&ts->links);
+ _pr_numFreeStacks--;
+ ts->links.next = 0;
+ ts->links.prev = 0;
+ PR_Unlock(_pr_stackLock);
+ goto done;
+ }
+ ts = 0;
}
PR_Unlock(_pr_stackLock);
if (!ts) {
- /* Make a new thread stack object. */
- ts = PR_NEWZAP(PRThreadStack);
- if (!ts) {
- return NULL;
- }
-
- /*
- ** Assign some of the virtual space to the new stack object. We
- ** may not get that piece of VM, but if nothing else we will
- ** advance the pointer so we don't collide (unless the OS screws
- ** up).
- */
- ts->allocSize = stackSize + 2*REDZONE;
- ts->seg = _PR_NewSegment(ts->allocSize, 0);
- if (!ts->seg) {
- PR_DELETE(ts);
- return NULL;
- }
- }
-
- done:
+ /* Make a new thread stack object. */
+ ts = PR_NEWZAP(PRThreadStack);
+ if (!ts) {
+ return NULL;
+ }
+
+ /*
+ ** Assign some of the virtual space to the new stack object. We
+ ** may not get that piece of VM, but if nothing else we will
+ ** advance the pointer so we don't collide (unless the OS screws
+ ** up).
+ */
+ ts->allocSize = stackSize + 2*REDZONE;
+ ts->seg = _PR_NewSegment(ts->allocSize, 0);
+ if (!ts->seg) {
+ PR_DELETE(ts);
+ return NULL;
+ }
+ }
+
+done:
ts->allocBase = (char*)ts->seg->vaddr;
ts->flags = _PR_STACK_MAPPED;
ts->stackSize = stackSize;
@@ -137,11 +138,11 @@ PRThreadStack *_PR_NewStack(PRUint32 stackSize)
#endif
PR_LOG(_pr_thread_lm, PR_LOG_NOTICE,
- ("thread stack: base=0x%x limit=0x%x bottom=0x%x top=0x%x\n",
- ts->allocBase, ts->allocBase + ts->allocSize - 1,
- ts->allocBase + REDZONE,
- ts->allocBase + REDZONE + stackSize - 1));
-
+ ("thread stack: base=0x%x limit=0x%x bottom=0x%x top=0x%x\n",
+ ts->allocBase, ts->allocBase + ts->allocSize - 1,
+ ts->allocBase + REDZONE,
+ ts->allocBase + REDZONE + stackSize - 1));
+
_PR_MD_INIT_STACK(ts,REDZONE);
return ts;
@@ -153,11 +154,11 @@ PRThreadStack *_PR_NewStack(PRUint32 stackSize)
void _PR_FreeStack(PRThreadStack *ts)
{
if (!ts) {
- return;
+ return;
}
if (ts->flags & _PR_STACK_PRIMORDIAL) {
- PR_DELETE(ts);
- return;
+ PR_DELETE(ts);
+ return;
}
/*
diff --git a/nsprpub/pr/src/threads/combined/pruthr.c b/nsprpub/pr/src/threads/combined/pruthr.c
index 4625ab246..44a082007 100644
--- a/nsprpub/pr/src/threads/combined/pruthr.c
+++ b/nsprpub/pr/src/threads/combined/pruthr.c
@@ -7,7 +7,7 @@
#include <signal.h>
#include <string.h>
-#if defined(WIN95)
+#if defined(WIN95)
/*
** Some local variables report warnings on Win95 because the code paths
** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
@@ -15,7 +15,7 @@
**
*/
#pragma warning(disable : 4101)
-#endif
+#endif
/* _pr_activeLock protects the following global variables */
PRLock *_pr_activeLock;
@@ -28,7 +28,7 @@ PRInt32 _pr_primordialExitCount; /* In PR_Cleanup(), the primordial thread
* If the primordial thread is a system
* thread, then _pr_primordialExitCount
* is 0. If the primordial thread is
- * itself a user thread, then
+ * itself a user thread, then
* _pr_primordialThread is 1.
*/
PRCondVar *_pr_primordialExitCVar; /* When _pr_userActive is decremented to
@@ -60,7 +60,7 @@ static void _PR_InitializeRecycledThread(PRThread *thread);
static void _PR_UserRunThread(void);
void _PR_InitThreads(PRThreadType type, PRThreadPriority priority,
- PRUintn maxPTDs)
+ PRUintn maxPTDs)
{
PRThread *thread;
PRThreadStack *stack;
@@ -74,13 +74,13 @@ void _PR_InitThreads(PRThreadType type, PRThreadPriority priority,
stack = PR_NEWZAP(PRThreadStack);
#ifdef HAVE_STACK_GROWING_UP
stack->stackTop = (char*) ((((PRWord)&type) >> _pr_pageShift)
- << _pr_pageShift);
+ << _pr_pageShift);
#else
#if defined(SOLARIS) || defined (UNIXWARE) && defined (USR_SVR4_THREADS)
stack->stackTop = (char*) &thread;
#else
stack->stackTop = (char*) ((((PRWord)&type + _pr_pageSize - 1)
- >> _pr_pageShift) << _pr_pageShift);
+ >> _pr_pageShift) << _pr_pageShift);
#endif
#endif
#else
@@ -104,11 +104,13 @@ void _PR_InitThreads(PRThreadType type, PRThreadPriority priority,
_pr_userActive++;
_pr_primordialExitCount = 1;
}
- thread->no_sched = 1;
- _pr_primordialExitCVar = PR_NewCondVar(_pr_activeLock);
+ thread->no_sched = 1;
+ _pr_primordialExitCVar = PR_NewCondVar(_pr_activeLock);
}
- if (!thread) PR_Abort();
+ if (!thread) {
+ PR_Abort();
+ }
#ifdef _PR_LOCAL_THREADS_ONLY
thread->flags |= _PR_PRIMORDIAL;
#else
@@ -174,13 +176,13 @@ static void _PR_InitializeNativeStack(PRThreadStack *ts)
** Setup stackTop and stackBottom values.
*/
#ifdef HAVE_STACK_GROWING_UP
- ts->allocBase = (char*) ((((PRWord)&ts) >> _pr_pageShift)
- << _pr_pageShift);
+ ts->allocBase = (char*) ((((PRWord)&ts) >> _pr_pageShift)
+ << _pr_pageShift);
ts->stackBottom = ts->allocBase + ts->stackSize;
ts->stackTop = ts->allocBase;
#else
ts->allocBase = (char*) ((((PRWord)&ts + _pr_pageSize - 1)
- >> _pr_pageShift) << _pr_pageShift);
+ >> _pr_pageShift) << _pr_pageShift);
ts->stackTop = ts->allocBase;
ts->stackBottom = ts->allocBase - ts->stackSize;
#endif
@@ -195,7 +197,7 @@ void _PR_NotifyJoinWaiters(PRThread *thread)
** Notify on our "termination" condition variable so that joining
** thread will know about our termination. Switch our context and
** come back later on to continue the cleanup.
- */
+ */
PR_ASSERT(thread == _PR_MD_CURRENT_THREAD());
if (thread->term != NULL) {
PR_Lock(_pr_terminationCVLock);
@@ -251,19 +253,19 @@ static void _PR_InitializeRecycledThread(PRThread *thread)
PRStatus _PR_RecycleThread(PRThread *thread)
{
if ( _PR_IS_NATIVE_THREAD(thread) &&
- _PR_NUM_DEADNATIVE < _pr_recycleThreads) {
+ _PR_NUM_DEADNATIVE < _pr_recycleThreads) {
_PR_DEADQ_LOCK;
PR_APPEND_LINK(&thread->links, &_PR_DEADNATIVEQ);
_PR_INC_DEADNATIVE;
_PR_DEADQ_UNLOCK;
- return (PR_SUCCESS);
+ return (PR_SUCCESS);
} else if ( !_PR_IS_NATIVE_THREAD(thread) &&
_PR_NUM_DEADUSER < _pr_recycleThreads) {
_PR_DEADQ_LOCK;
PR_APPEND_LINK(&thread->links, &_PR_DEADUSERQ);
_PR_INC_DEADUSER;
_PR_DEADQ_UNLOCK;
- return (PR_SUCCESS);
+ return (PR_SUCCESS);
}
return (PR_FAILURE);
}
@@ -433,7 +435,7 @@ void _PR_NativeRunThread(void *arg)
thread->state = _PR_DEAD_STATE;
if (!_pr_recycleThreads || (_PR_RecycleThread(thread) ==
- PR_FAILURE)) {
+ PR_FAILURE)) {
/*
* thread not recycled
* platform-specific thread exit processing
@@ -460,8 +462,9 @@ static void _PR_UserRunThread(void)
PRThread *thread = _PR_MD_CURRENT_THREAD();
PRIntn is;
- if (_MD_LAST_THREAD())
- _MD_LAST_THREAD()->no_sched = 0;
+ if (_MD_LAST_THREAD()) {
+ _MD_LAST_THREAD()->no_sched = 0;
+ }
#ifdef HAVE_CUSTOM_USER_THREADS
if (thread->stack == NULL) {
@@ -472,17 +475,19 @@ static void _PR_UserRunThread(void)
while(1) {
/* Run thread main */
- if ( !_PR_IS_NATIVE_THREAD(thread)) _PR_MD_SET_INTSOFF(0);
+ if ( !_PR_IS_NATIVE_THREAD(thread)) {
+ _PR_MD_SET_INTSOFF(0);
+ }
- /*
- * Add to list of active threads
- */
- if (!(thread->flags & _PR_IDLE_THREAD)) {
- PR_Lock(_pr_activeLock);
- PR_APPEND_LINK(&thread->active, &_PR_ACTIVE_LOCAL_THREADQ());
- _pr_local_threads++;
- PR_Unlock(_pr_activeLock);
- }
+ /*
+ * Add to list of active threads
+ */
+ if (!(thread->flags & _PR_IDLE_THREAD)) {
+ PR_Lock(_pr_activeLock);
+ PR_APPEND_LINK(&thread->active, &_PR_ACTIVE_LOCAL_THREADQ());
+ _pr_local_threads++;
+ PR_Unlock(_pr_activeLock);
+ }
(*thread->startFunc)(thread->arg);
@@ -504,33 +509,33 @@ static void _PR_UserRunThread(void)
PR_ASSERT(thread->io_suspended == PR_FALSE);
PR_Lock(_pr_activeLock);
- /*
- * remove thread from list of active threads
- */
- if (!(thread->flags & _PR_IDLE_THREAD)) {
- PR_REMOVE_LINK(&thread->active);
- _pr_local_threads--;
- }
- PR_Unlock(_pr_activeLock);
+ /*
+ * remove thread from list of active threads
+ */
+ if (!(thread->flags & _PR_IDLE_THREAD)) {
+ PR_REMOVE_LINK(&thread->active);
+ _pr_local_threads--;
+ }
+ PR_Unlock(_pr_activeLock);
PR_LOG(_pr_thread_lm, PR_LOG_MIN, ("thread exiting"));
/* All done, time to go away */
_PR_CleanupThread(thread);
- _PR_INTSOFF(is);
+ _PR_INTSOFF(is);
_PR_NotifyJoinWaiters(thread);
- _PR_DecrActiveThreadCount(thread);
+ _PR_DecrActiveThreadCount(thread);
thread->state = _PR_DEAD_STATE;
if (!_pr_recycleThreads || (_PR_RecycleThread(thread) ==
- PR_FAILURE)) {
+ PR_FAILURE)) {
/*
** Destroy the thread resources
*/
- _PR_UserDestroyThread(thread);
+ _PR_UserDestroyThread(thread);
}
/*
@@ -557,54 +562,58 @@ void _PR_SetThreadPriority(PRThread *thread, PRThreadPriority newPri)
return;
}
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_THREAD_LOCK(thread);
if (newPri != thread->priority) {
- _PRCPU *cpu = thread->cpu;
+ _PRCPU *cpu = thread->cpu;
- switch (thread->state) {
- case _PR_RUNNING:
- /* Change my priority */
+ switch (thread->state) {
+ case _PR_RUNNING:
+ /* Change my priority */
- _PR_RUNQ_LOCK(cpu);
- thread->priority = newPri;
- if (_PR_RUNQREADYMASK(cpu) >> (newPri + 1)) {
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_SET_RESCHED_FLAG();
- }
- _PR_RUNQ_UNLOCK(cpu);
- break;
+ _PR_RUNQ_LOCK(cpu);
+ thread->priority = newPri;
+ if (_PR_RUNQREADYMASK(cpu) >> (newPri + 1)) {
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_SET_RESCHED_FLAG();
+ }
+ }
+ _PR_RUNQ_UNLOCK(cpu);
+ break;
- case _PR_RUNNABLE:
+ case _PR_RUNNABLE:
- _PR_RUNQ_LOCK(cpu);
- /* Move to different runQ */
- _PR_DEL_RUNQ(thread);
- thread->priority = newPri;
- PR_ASSERT(!(thread->flags & _PR_IDLE_THREAD));
- _PR_ADD_RUNQ(thread, cpu, newPri);
- _PR_RUNQ_UNLOCK(cpu);
+ _PR_RUNQ_LOCK(cpu);
+ /* Move to different runQ */
+ _PR_DEL_RUNQ(thread);
+ thread->priority = newPri;
+ PR_ASSERT(!(thread->flags & _PR_IDLE_THREAD));
+ _PR_ADD_RUNQ(thread, cpu, newPri);
+ _PR_RUNQ_UNLOCK(cpu);
- if (newPri > me->priority) {
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_SET_RESCHED_FLAG();
- }
+ if (newPri > me->priority) {
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_SET_RESCHED_FLAG();
+ }
+ }
- break;
+ break;
- case _PR_LOCK_WAIT:
- case _PR_COND_WAIT:
- case _PR_IO_WAIT:
- case _PR_SUSPENDED:
+ case _PR_LOCK_WAIT:
+ case _PR_COND_WAIT:
+ case _PR_IO_WAIT:
+ case _PR_SUSPENDED:
- thread->priority = newPri;
- break;
- }
+ thread->priority = newPri;
+ break;
+ }
}
_PR_THREAD_UNLOCK(thread);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSON(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
}
/*
@@ -618,51 +627,53 @@ static void _PR_Suspend(PRThread *thread)
PR_ASSERT(thread != me);
PR_ASSERT(!_PR_IS_NATIVE_THREAD(thread) || (!thread->cpu));
- if (!_PR_IS_NATIVE_THREAD(me))
+ if (!_PR_IS_NATIVE_THREAD(me)) {
_PR_INTSOFF(is);
+ }
_PR_THREAD_LOCK(thread);
switch (thread->state) {
- case _PR_RUNNABLE:
- if (!_PR_IS_NATIVE_THREAD(thread)) {
- _PR_RUNQ_LOCK(thread->cpu);
- _PR_DEL_RUNQ(thread);
- _PR_RUNQ_UNLOCK(thread->cpu);
+ case _PR_RUNNABLE:
+ if (!_PR_IS_NATIVE_THREAD(thread)) {
+ _PR_RUNQ_LOCK(thread->cpu);
+ _PR_DEL_RUNQ(thread);
+ _PR_RUNQ_UNLOCK(thread->cpu);
+
+ _PR_MISCQ_LOCK(thread->cpu);
+ _PR_ADD_SUSPENDQ(thread, thread->cpu);
+ _PR_MISCQ_UNLOCK(thread->cpu);
+ } else {
+ /*
+ * Only LOCAL threads are suspended by _PR_Suspend
+ */
+ PR_ASSERT(0);
+ }
+ thread->state = _PR_SUSPENDED;
+ break;
- _PR_MISCQ_LOCK(thread->cpu);
- _PR_ADD_SUSPENDQ(thread, thread->cpu);
- _PR_MISCQ_UNLOCK(thread->cpu);
- } else {
+ case _PR_RUNNING:
/*
- * Only LOCAL threads are suspended by _PR_Suspend
+ * The thread being suspended should be a LOCAL thread with
+ * _pr_numCPUs == 1. Hence, the thread cannot be in RUNNING state
*/
- PR_ASSERT(0);
- }
- thread->state = _PR_SUSPENDED;
- break;
-
- case _PR_RUNNING:
- /*
- * The thread being suspended should be a LOCAL thread with
- * _pr_numCPUs == 1. Hence, the thread cannot be in RUNNING state
- */
- PR_ASSERT(0);
- break;
+ PR_ASSERT(0);
+ break;
- case _PR_LOCK_WAIT:
- case _PR_IO_WAIT:
- case _PR_COND_WAIT:
- if (_PR_IS_NATIVE_THREAD(thread)) {
- _PR_MD_SUSPEND_THREAD(thread);
- }
- thread->flags |= _PR_SUSPENDING;
- break;
+ case _PR_LOCK_WAIT:
+ case _PR_IO_WAIT:
+ case _PR_COND_WAIT:
+ if (_PR_IS_NATIVE_THREAD(thread)) {
+ _PR_MD_SUSPEND_THREAD(thread);
+ }
+ thread->flags |= _PR_SUSPENDING;
+ break;
- default:
- PR_Abort();
+ default:
+ PR_Abort();
}
_PR_THREAD_UNLOCK(thread);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSON(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
}
static void _PR_Resume(PRThread *thread)
@@ -671,72 +682,75 @@ static void _PR_Resume(PRThread *thread)
PRIntn is;
PRThread *me = _PR_MD_CURRENT_THREAD();
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_THREAD_LOCK(thread);
switch (thread->state) {
- case _PR_SUSPENDED:
- thread->state = _PR_RUNNABLE;
- thread->flags &= ~_PR_SUSPENDING;
- if (!_PR_IS_NATIVE_THREAD(thread)) {
- _PR_MISCQ_LOCK(thread->cpu);
- _PR_DEL_SUSPENDQ(thread);
- _PR_MISCQ_UNLOCK(thread->cpu);
+ case _PR_SUSPENDED:
+ thread->state = _PR_RUNNABLE;
+ thread->flags &= ~_PR_SUSPENDING;
+ if (!_PR_IS_NATIVE_THREAD(thread)) {
+ _PR_MISCQ_LOCK(thread->cpu);
+ _PR_DEL_SUSPENDQ(thread);
+ _PR_MISCQ_UNLOCK(thread->cpu);
+
+ pri = thread->priority;
+
+ _PR_RUNQ_LOCK(thread->cpu);
+ _PR_ADD_RUNQ(thread, thread->cpu, pri);
+ _PR_RUNQ_UNLOCK(thread->cpu);
+
+ if (pri > _PR_MD_CURRENT_THREAD()->priority) {
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_SET_RESCHED_FLAG();
+ }
+ }
+ } else {
+ PR_ASSERT(0);
+ }
+ break;
- pri = thread->priority;
+ case _PR_IO_WAIT:
+ case _PR_COND_WAIT:
+ thread->flags &= ~_PR_SUSPENDING;
+ /* PR_ASSERT(thread->wait.monitor->stickyCount == 0); */
+ break;
- _PR_RUNQ_LOCK(thread->cpu);
- _PR_ADD_RUNQ(thread, thread->cpu, pri);
- _PR_RUNQ_UNLOCK(thread->cpu);
+ case _PR_LOCK_WAIT:
+ {
+ PRLock *wLock = thread->wait.lock;
+
+ thread->flags &= ~_PR_SUSPENDING;
- if (pri > _PR_MD_CURRENT_THREAD()->priority) {
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_SET_RESCHED_FLAG();
+ _PR_LOCK_LOCK(wLock);
+ if (thread->wait.lock->owner == 0) {
+ _PR_UnblockLockWaiter(thread->wait.lock);
}
- } else {
- PR_ASSERT(0);
+ _PR_LOCK_UNLOCK(wLock);
+ break;
}
- break;
-
- case _PR_IO_WAIT:
- case _PR_COND_WAIT:
- thread->flags &= ~_PR_SUSPENDING;
-/* PR_ASSERT(thread->wait.monitor->stickyCount == 0); */
- break;
-
- case _PR_LOCK_WAIT:
- {
- PRLock *wLock = thread->wait.lock;
-
- thread->flags &= ~_PR_SUSPENDING;
-
- _PR_LOCK_LOCK(wLock);
- if (thread->wait.lock->owner == 0) {
- _PR_UnblockLockWaiter(thread->wait.lock);
- }
- _PR_LOCK_UNLOCK(wLock);
- break;
- }
- case _PR_RUNNABLE:
- break;
- case _PR_RUNNING:
- /*
- * The thread being suspended should be a LOCAL thread with
- * _pr_numCPUs == 1. Hence, the thread cannot be in RUNNING state
- */
- PR_ASSERT(0);
- break;
+ case _PR_RUNNABLE:
+ break;
+ case _PR_RUNNING:
+ /*
+ * The thread being suspended should be a LOCAL thread with
+ * _pr_numCPUs == 1. Hence, the thread cannot be in RUNNING state
+ */
+ PR_ASSERT(0);
+ break;
- default:
- /*
- * thread should have been in one of the above-listed blocked states
- * (_PR_JOIN_WAIT, _PR_IO_WAIT, _PR_UNBORN, _PR_DEAD_STATE)
- */
- PR_Abort();
+ default:
+ /*
+ * thread should have been in one of the above-listed blocked states
+ * (_PR_JOIN_WAIT, _PR_IO_WAIT, _PR_UNBORN, _PR_DEAD_STATE)
+ */
+ PR_Abort();
}
_PR_THREAD_UNLOCK(thread);
- if (!_PR_IS_NATIVE_THREAD(me))
+ if (!_PR_IS_NATIVE_THREAD(me)) {
_PR_INTSON(is);
+ }
}
@@ -761,8 +775,8 @@ static PRThread *get_thread(_PRCPU *cpu, PRBool *wakeup_cpus)
}
thread = NULL;
for (pri = priMax; pri >= priMin ; pri-- ) {
- if (r & (1 << pri)) {
- for (qp = _PR_RUNQ(cpu)[pri].next;
+ if (r & (1 << pri)) {
+ for (qp = _PR_RUNQ(cpu)[pri].next;
qp != &_PR_RUNQ(cpu)[pri];
qp = qp->next) {
thread = _PR_THREAD_PTR(qp);
@@ -786,9 +800,6 @@ static PRThread *get_thread(_PRCPU *cpu, PRBool *wakeup_cpus)
*/
thread = NULL;
-#ifdef IRIX
- _PR_MD_WAKEUP_PRIMORDIAL_CPU();
-#endif
continue;
} else if (thread->io_pending == PR_TRUE) {
/*
@@ -854,16 +865,16 @@ void _PR_Schedule(void)
* operation, for example
*/
if ((thread = suspendAllThread) != 0) {
- if ((!(thread->no_sched)) && (thread->state == _PR_RUNNABLE)) {
+ if ((!(thread->no_sched)) && (thread->state == _PR_RUNNABLE)) {
/* Pull thread off of its run queue */
_PR_DEL_RUNQ(thread);
_PR_RUNQ_UNLOCK(cpu);
goto found_thread;
- } else {
+ } else {
thread = NULL;
_PR_RUNQ_UNLOCK(cpu);
goto idle_thread;
- }
+ }
}
r = _PR_RUNQREADYMASK(cpu);
if (r==0) {
@@ -876,8 +887,8 @@ void _PR_Schedule(void)
}
thread = NULL;
for (pri = priMax; pri >= priMin ; pri-- ) {
- if (r & (1 << pri)) {
- for (qp = _PR_RUNQ(cpu)[pri].next;
+ if (r & (1 << pri)) {
+ for (qp = _PR_RUNQ(cpu)[pri].next;
qp != &_PR_RUNQ(cpu)[pri];
qp = qp->next) {
thread = _PR_THREAD_PTR(qp);
@@ -885,7 +896,7 @@ void _PR_Schedule(void)
* skip non-schedulable threads
*/
PR_ASSERT(!(thread->flags & _PR_IDLE_THREAD));
- if ((thread->no_sched) && (me != thread)){
+ if ((thread->no_sched) && (me != thread)) {
thread = NULL;
continue;
} else {
@@ -907,48 +918,51 @@ void _PR_Schedule(void)
for (qp = _PR_CPUQ().next; qp != &_PR_CPUQ(); qp = qp->next) {
if (cpu != _PR_CPU_PTR(qp)) {
if ((thread = get_thread(_PR_CPU_PTR(qp), &wakeup_cpus))
- != NULL) {
+ != NULL) {
thread->cpu = cpu;
_PR_CPU_LIST_UNLOCK();
- if (wakeup_cpus == PR_TRUE)
+ if (wakeup_cpus == PR_TRUE) {
_PR_MD_WAKEUP_CPUS();
+ }
goto found_thread;
}
}
}
_PR_CPU_LIST_UNLOCK();
- if (wakeup_cpus == PR_TRUE)
+ if (wakeup_cpus == PR_TRUE) {
_PR_MD_WAKEUP_CPUS();
+ }
#endif /* _PR_LOCAL_THREADS_ONLY */
idle_thread:
- /*
- ** There are no threads to run. Switch to the idle thread
- */
+ /*
+ ** There are no threads to run. Switch to the idle thread
+ */
PR_LOG(_pr_sched_lm, PR_LOG_MAX, ("pausing"));
thread = _PR_MD_CURRENT_CPU()->idle_thread;
found_thread:
PR_ASSERT((me == thread) || ((thread->state == _PR_RUNNABLE) &&
- (!(thread->no_sched))));
+ (!(thread->no_sched))));
/* Resume the thread */
PR_LOG(_pr_sched_lm, PR_LOG_MAX,
- ("switching to %d[%p]", thread->id, thread));
+ ("switching to %d[%p]", thread->id, thread));
PR_ASSERT(thread->state != _PR_RUNNING);
thread->state = _PR_RUNNING;
-
+
/* If we are on the runq, it just means that we went to sleep on some
* resource, and by the time we got here another real native thread had
- * already given us the resource and put us back on the runqueue
+ * already given us the resource and put us back on the runqueue
*/
- PR_ASSERT(thread->cpu == _PR_MD_CURRENT_CPU());
- if (thread != me)
+ PR_ASSERT(thread->cpu == _PR_MD_CURRENT_CPU());
+ if (thread != me) {
_PR_MD_RESTORE_CONTEXT(thread);
+ }
#if 0
- /* XXXMB; with setjmp/longjmp it is impossible to land here, but
- * it is not with fibers... Is this a bad thing? I believe it is
+ /* XXXMB; with setjmp/longjmp it is impossible to land here, but
+ * it is not with fibers... Is this a bad thing? I believe it is
* still safe.
*/
PR_NOT_REACHED("impossible return from schedule");
@@ -956,13 +970,13 @@ found_thread:
}
/*
-** Attaches a thread.
-** Does not set the _PR_MD_CURRENT_THREAD.
+** Attaches a thread.
+** Does not set the _PR_MD_CURRENT_THREAD.
** Does not specify the scope of the thread.
*/
static PRThread *
_PR_AttachThread(PRThreadType type, PRThreadPriority priority,
- PRThreadStack *stack)
+ PRThreadStack *stack)
{
PRThread *thread;
char *mem;
@@ -981,9 +995,9 @@ _PR_AttachThread(PRThreadType type, PRThreadPriority priority,
thread->state = _PR_RUNNING;
PR_INIT_CLIST(&thread->lockList);
if (_PR_MD_NEW_LOCK(&thread->threadLock) == PR_FAILURE) {
- PR_DELETE(thread);
- return 0;
- }
+ PR_DELETE(thread);
+ return 0;
+ }
return thread;
}
@@ -992,15 +1006,15 @@ _PR_AttachThread(PRThreadType type, PRThreadPriority priority,
-PR_IMPLEMENT(PRThread*)
+PR_IMPLEMENT(PRThread*)
_PR_NativeCreateThread(PRThreadType type,
- void (*start)(void *arg),
- void *arg,
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize,
- PRUint32 flags)
+ void (*start)(void *arg),
+ void *arg,
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize,
+ PRUint32 flags)
{
PRThread *thread;
@@ -1028,33 +1042,33 @@ _PR_NativeCreateThread(PRThreadType type,
thread->startFunc = start;
thread->arg = arg;
- /*
+ /*
Set thread flags related to scope and joinable state. If joinable
thread, allocate a "termination" conidition variable.
*/
if (state == PR_JOINABLE_THREAD) {
thread->term = PR_NewCondVar(_pr_terminationCVLock);
- if (thread->term == NULL) {
- PR_DELETE(thread->stack);
- goto done;
- }
+ if (thread->term == NULL) {
+ PR_DELETE(thread->stack);
+ goto done;
+ }
}
- thread->state = _PR_RUNNING;
+ thread->state = _PR_RUNNING;
if (_PR_MD_CREATE_THREAD(thread, _PR_NativeRunThread, priority,
- scope,state,stackSize) == PR_SUCCESS) {
+ scope,state,stackSize) == PR_SUCCESS) {
return thread;
}
if (thread->term) {
PR_DestroyCondVar(thread->term);
thread->term = NULL;
}
- PR_DELETE(thread->stack);
+ PR_DELETE(thread->stack);
}
done:
if (thread) {
- _PR_DecrActiveThreadCount(thread);
+ _PR_DecrActiveThreadCount(thread);
_PR_DestroyThread(thread);
}
return NULL;
@@ -1063,13 +1077,13 @@ done:
/************************************************************************/
PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
- void (*start)(void *arg),
- void *arg,
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize,
- PRUint32 flags)
+ void (*start)(void *arg),
+ void *arg,
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize,
+ PRUint32 flags)
{
PRThread *me;
PRThread *thread = NULL;
@@ -1080,7 +1094,7 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
PRIntn useRecycled = 0;
PRBool status;
- /*
+ /*
First, pin down the priority. Not all compilers catch passing out of
range enum here. If we let bad values thru, priority queues won't work.
*/
@@ -1089,34 +1103,39 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
} else if (priority < PR_PRIORITY_FIRST) {
priority = PR_PRIORITY_FIRST;
}
-
- if (!_pr_initialized) _PR_ImplicitInitialization();
- if (! (flags & _PR_IDLE_THREAD))
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+
+ if (! (flags & _PR_IDLE_THREAD)) {
me = _PR_MD_CURRENT_THREAD();
+ }
#if defined(_PR_GLOBAL_THREADS_ONLY)
- /*
- * can create global threads only
- */
- if (scope == PR_LOCAL_THREAD)
- scope = PR_GLOBAL_THREAD;
+ /*
+ * can create global threads only
+ */
+ if (scope == PR_LOCAL_THREAD) {
+ scope = PR_GLOBAL_THREAD;
+ }
#endif
- if (_native_threads_only)
- scope = PR_GLOBAL_THREAD;
+ if (_native_threads_only) {
+ scope = PR_GLOBAL_THREAD;
+ }
native = (((scope == PR_GLOBAL_THREAD)|| (scope == PR_GLOBAL_BOUND_THREAD))
- && _PR_IS_NATIVE_THREAD_SUPPORTED());
+ && _PR_IS_NATIVE_THREAD_SUPPORTED());
_PR_ADJUST_STACKSIZE(stackSize);
if (native) {
- /*
- * clear the IDLE_THREAD flag which applies to LOCAL
- * threads only
- */
- flags &= ~_PR_IDLE_THREAD;
+ /*
+ * clear the IDLE_THREAD flag which applies to LOCAL
+ * threads only
+ */
+ flags &= ~_PR_IDLE_THREAD;
flags |= _PR_GLOBAL_SCOPE;
if (_PR_NUM_DEADNATIVE > 0) {
_PR_DEADQ_LOCK;
@@ -1132,35 +1151,38 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
_PR_InitializeRecycledThread(thread);
thread->startFunc = start;
thread->arg = arg;
- thread->flags = (flags | _PR_GLOBAL_SCOPE);
- if (type == PR_SYSTEM_THREAD)
- {
- thread->flags |= _PR_SYSTEM;
- PR_ATOMIC_INCREMENT(&_pr_systemActive);
- }
- else PR_ATOMIC_INCREMENT(&_pr_userActive);
+ thread->flags = (flags | _PR_GLOBAL_SCOPE);
+ if (type == PR_SYSTEM_THREAD)
+ {
+ thread->flags |= _PR_SYSTEM;
+ PR_ATOMIC_INCREMENT(&_pr_systemActive);
+ }
+ else {
+ PR_ATOMIC_INCREMENT(&_pr_userActive);
+ }
- if (state == PR_JOINABLE_THREAD) {
- if (!thread->term)
- thread->term = PR_NewCondVar(_pr_terminationCVLock);
- }
- else {
- if(thread->term) {
- PR_DestroyCondVar(thread->term);
+ if (state == PR_JOINABLE_THREAD) {
+ if (!thread->term) {
+ thread->term = PR_NewCondVar(_pr_terminationCVLock);
+ }
+ }
+ else {
+ if(thread->term) {
+ PR_DestroyCondVar(thread->term);
thread->term = 0;
- }
- }
+ }
+ }
thread->priority = priority;
- _PR_MD_SET_PRIORITY(&(thread->md), priority);
- /* XXX what about stackSize? */
- thread->state = _PR_RUNNING;
+ _PR_MD_SET_PRIORITY(&(thread->md), priority);
+ /* XXX what about stackSize? */
+ thread->state = _PR_RUNNING;
_PR_MD_WAKEUP_WAITER(thread);
- return thread;
+ return thread;
}
}
- thread = _PR_NativeCreateThread(type, start, arg, priority,
- scope, state, stackSize, flags);
+ thread = _PR_NativeCreateThread(type, start, arg, priority,
+ scope, state, stackSize, flags);
} else {
if (_PR_NUM_DEADUSER > 0) {
_PR_DEADQ_LOCK;
@@ -1170,14 +1192,14 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
} else {
PRCList *ptr;
- /* Go down list checking for a recycled thread with a
+ /* Go down list checking for a recycled thread with a
* large enough stack. XXXMB - this has a bad degenerate case.
*/
ptr = _PR_DEADUSERQ.next;
while( ptr != &_PR_DEADUSERQ ) {
thread = _PR_THREAD_PTR(ptr);
if ((thread->stack->stackSize >= stackSize) &&
- (!thread->no_sched)) {
+ (!thread->no_sched)) {
PR_REMOVE_LINK(&thread->links);
_PR_DEC_DEADUSER;
break;
@@ -1185,28 +1207,29 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
ptr = ptr->next;
thread = NULL;
}
- }
+ }
_PR_DEADQ_UNLOCK;
- if (thread) {
+ if (thread) {
_PR_InitializeRecycledThread(thread);
thread->startFunc = start;
thread->arg = arg;
thread->priority = priority;
- if (state == PR_JOINABLE_THREAD) {
- if (!thread->term)
- thread->term = PR_NewCondVar(_pr_terminationCVLock);
- } else {
- if(thread->term) {
- PR_DestroyCondVar(thread->term);
- thread->term = 0;
- }
- }
+ if (state == PR_JOINABLE_THREAD) {
+ if (!thread->term) {
+ thread->term = PR_NewCondVar(_pr_terminationCVLock);
+ }
+ } else {
+ if(thread->term) {
+ PR_DestroyCondVar(thread->term);
+ thread->term = 0;
+ }
+ }
useRecycled++;
}
}
- }
+ }
if (thread == NULL) {
#ifndef HAVE_CUSTOM_USER_THREADS
stack = _PR_NewStack(stackSize);
@@ -1260,8 +1283,9 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
PR_INIT_CLIST(&thread->lockList);
if (_PR_MD_INIT_THREAD(thread) == PR_FAILURE) {
- if (thread->threadAllocatedOnStack == 1)
+ if (thread->threadAllocatedOnStack == 1) {
_PR_FreeStack(thread->stack);
+ }
else {
PR_DELETE(thread);
}
@@ -1270,8 +1294,9 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
}
if (_PR_MD_NEW_LOCK(&thread->threadLock) == PR_FAILURE) {
- if (thread->threadAllocatedOnStack == 1)
+ if (thread->threadAllocatedOnStack == 1) {
_PR_FreeStack(thread->stack);
+ }
else {
PR_DELETE(thread->privateData);
PR_DELETE(thread);
@@ -1284,8 +1309,9 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
if (status == PR_FALSE) {
_PR_MD_FREE_LOCK(&thread->threadLock);
- if (thread->threadAllocatedOnStack == 1)
+ if (thread->threadAllocatedOnStack == 1) {
_PR_FreeStack(thread->stack);
+ }
else {
PR_DELETE(thread->privateData);
PR_DELETE(thread);
@@ -1293,7 +1319,7 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
return NULL;
}
- /*
+ /*
Set thread flags related to scope and joinable state. If joinable
thread, allocate a "termination" condition variable.
*/
@@ -1301,8 +1327,9 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
thread->term = PR_NewCondVar(_pr_terminationCVLock);
if (thread->term == NULL) {
_PR_MD_FREE_LOCK(&thread->threadLock);
- if (thread->threadAllocatedOnStack == 1)
+ if (thread->threadAllocatedOnStack == 1) {
_PR_FreeStack(thread->stack);
+ }
else {
PR_DELETE(thread->privateData);
PR_DELETE(thread);
@@ -1310,9 +1337,9 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
return NULL;
}
}
-
+
}
-
+
/* Update thread type counter */
PR_Lock(_pr_activeLock);
thread->flags = flags;
@@ -1326,15 +1353,17 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
/* Make thread runnable */
thread->state = _PR_RUNNABLE;
- /*
- * Add to list of active threads
- */
+ /*
+ * Add to list of active threads
+ */
PR_Unlock(_pr_activeLock);
- if ((! (thread->flags & _PR_IDLE_THREAD)) && _PR_IS_NATIVE_THREAD(me) )
+ if ((! (thread->flags & _PR_IDLE_THREAD)) && _PR_IS_NATIVE_THREAD(me) ) {
thread->cpu = _PR_GetPrimordialCPU();
- else
+ }
+ else {
thread->cpu = _PR_MD_CURRENT_CPU();
+ }
PR_ASSERT(!_PR_IS_NATIVE_THREAD(thread));
@@ -1350,28 +1379,29 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
** If the creating thread is a kernel thread, we need to
** awaken the user thread idle thread somehow; potentially
** it could be sleeping in its idle loop, and we need to poke
- ** it. To do so, wake the idle thread...
+ ** it. To do so, wake the idle thread...
*/
_PR_MD_WAKEUP_WAITER(NULL);
} else if (_PR_IS_NATIVE_THREAD(me)) {
_PR_MD_WAKEUP_WAITER(thread);
}
- if ((! (thread->flags & _PR_IDLE_THREAD)) && !_PR_IS_NATIVE_THREAD(me) )
+ if ((! (thread->flags & _PR_IDLE_THREAD)) && !_PR_IS_NATIVE_THREAD(me) ) {
_PR_INTSON(is);
+ }
}
return thread;
}
PR_IMPLEMENT(PRThread*) PR_CreateThread(PRThreadType type,
- void (*start)(void *arg),
- void *arg,
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+ void (*start)(void *arg),
+ void *arg,
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize)
{
- return _PR_CreateThread(type, start, arg, priority, scope, state,
+ return _PR_CreateThread(type, start, arg, priority, scope, state,
stackSize, 0);
}
@@ -1388,7 +1418,7 @@ PR_IMPLEMENT(PRThread*) PR_CreateThread(PRThreadType type,
** thread. PR_Init does this automatically for the primordial thread.
*/
PRThread* _PRI_AttachThread(PRThreadType type,
- PRThreadPriority priority, PRThreadStack *stack, PRUint32 flags)
+ PRThreadPriority priority, PRThreadStack *stack, PRUint32 flags)
{
PRThread *thread;
@@ -1419,9 +1449,9 @@ PRThread* _PRI_AttachThread(PRThreadType type,
PR_INIT_CLIST(&thread->links);
if (_PR_MD_INIT_ATTACHED_THREAD(thread) == PR_FAILURE) {
- PR_DELETE(thread->stack);
- _PR_DestroyThread(thread);
- return NULL;
+ PR_DELETE(thread->stack);
+ _PR_DestroyThread(thread);
+ return NULL;
}
_PR_MD_SET_CURRENT_CPU(NULL);
@@ -1445,7 +1475,7 @@ PRThread* _PRI_AttachThread(PRThreadType type,
}
PR_IMPLEMENT(PRThread*) PR_AttachThread(PRThreadType type,
- PRThreadPriority priority, PRThreadStack *stack)
+ PRThreadPriority priority, PRThreadStack *stack)
{
return PR_GetCurrentThread();
}
@@ -1453,16 +1483,17 @@ PR_IMPLEMENT(PRThread*) PR_AttachThread(PRThreadType type,
PR_IMPLEMENT(void) PR_DetachThread(void)
{
/*
- * On IRIX, Solaris, and Windows, foreign threads are detached when
+ * On Solaris, and Windows, foreign threads are detached when
* they terminate.
*/
-#if !defined(IRIX) && !defined(WIN32) \
+#if !defined(WIN32) \
&& !(defined(SOLARIS) && defined(_PR_GLOBAL_THREADS_ONLY))
PRThread *me;
if (_pr_initialized) {
me = _PR_MD_GET_ATTACHED_THREAD();
- if ((me != NULL) && (me->flags & _PR_ATTACHED))
+ if ((me != NULL) && (me->flags & _PR_ATTACHED)) {
_PRI_DetachThread();
+ }
}
#endif
}
@@ -1471,12 +1502,12 @@ void _PRI_DetachThread(void)
{
PRThread *me = _PR_MD_CURRENT_THREAD();
- if (me->flags & _PR_PRIMORDIAL) {
- /*
- * ignore, if primordial thread
- */
- return;
- }
+ if (me->flags & _PR_PRIMORDIAL) {
+ /*
+ * ignore, if primordial thread
+ */
+ return;
+ }
PR_ASSERT(me->flags & _PR_ATTACHED);
PR_ASSERT(_PR_IS_NATIVE_THREAD(me));
_PR_CleanupThread(me);
@@ -1486,17 +1517,18 @@ void _PRI_DetachThread(void)
_PR_MD_CLEAN_THREAD(me);
_PR_MD_SET_CURRENT_THREAD(NULL);
- if (!me->threadAllocatedOnStack)
+ if (!me->threadAllocatedOnStack) {
PR_DELETE(me->stack);
+ }
_PR_MD_FREE_LOCK(&me->threadLock);
PR_DELETE(me);
}
/*
** Wait for thread termination:
-** "thread" is the target thread
+** "thread" is the target thread
**
-** This can return PR_FAILURE if no joinable thread could be found
+** This can return PR_FAILURE if no joinable thread could be found
** corresponding to the specified target thread.
**
** The calling thread is suspended until the target thread completes.
@@ -1511,8 +1543,9 @@ PR_IMPLEMENT(PRStatus) PR_JoinThread(PRThread *thread)
PRCondVar *term;
PRThread *me = _PR_MD_CURRENT_THREAD();
- if (!_PR_IS_NATIVE_THREAD(me))
+ if (!_PR_IS_NATIVE_THREAD(me)) {
_PR_INTSOFF(is);
+ }
term = thread->term;
/* can't join a non-joinable thread */
if (term == NULL) {
@@ -1524,8 +1557,9 @@ PR_IMPLEMENT(PRStatus) PR_JoinThread(PRThread *thread)
if (term->condQ.next != &term->condQ) {
goto ErrorExit;
}
- if (!_PR_IS_NATIVE_THREAD(me))
+ if (!_PR_IS_NATIVE_THREAD(me)) {
_PR_INTSON(is);
+ }
/* wait for the target thread's termination cv invariant */
PR_Lock (_pr_terminationCVLock);
@@ -1533,14 +1567,15 @@ PR_IMPLEMENT(PRStatus) PR_JoinThread(PRThread *thread)
(void) PR_WaitCondVar(term, PR_INTERVAL_NO_TIMEOUT);
}
(void) PR_Unlock (_pr_terminationCVLock);
-
- /*
+
+ /*
Remove target thread from global waiting to join Q; make it runnable
again and put it back on its run Q. When it gets scheduled later in
_PR_RunThread code, it will clean up its stack.
- */
- if (!_PR_IS_NATIVE_THREAD(me))
+ */
+ if (!_PR_IS_NATIVE_THREAD(me)) {
_PR_INTSOFF(is);
+ }
thread->state = _PR_RUNNABLE;
if ( !_PR_IS_NATIVE_THREAD(thread) ) {
_PR_THREAD_LOCK(thread);
@@ -1552,23 +1587,26 @@ PR_IMPLEMENT(PRStatus) PR_JoinThread(PRThread *thread)
_PR_AddThreadToRunQ(me, thread);
_PR_THREAD_UNLOCK(thread);
}
- if (!_PR_IS_NATIVE_THREAD(me))
+ if (!_PR_IS_NATIVE_THREAD(me)) {
_PR_INTSON(is);
+ }
_PR_MD_WAKEUP_WAITER(thread);
return PR_SUCCESS;
ErrorExit:
- if ( !_PR_IS_NATIVE_THREAD(me)) _PR_INTSON(is);
- return PR_FAILURE;
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
+ return PR_FAILURE;
}
PR_IMPLEMENT(void) PR_SetThreadPriority(PRThread *thread,
- PRThreadPriority newPri)
+ PRThreadPriority newPri)
{
- /*
+ /*
First, pin down the priority. Not all compilers catch passing out of
range enum here. If we let bad values thru, priority queues won't work.
*/
@@ -1577,11 +1615,13 @@ PR_IMPLEMENT(void) PR_SetThreadPriority(PRThread *thread,
} else if ((PRIntn)newPri < (PRIntn)PR_PRIORITY_FIRST) {
newPri = PR_PRIORITY_FIRST;
}
-
+
if ( _PR_IS_NATIVE_THREAD(thread) ) {
thread->priority = newPri;
_PR_MD_SET_PRIORITY(&(thread->md), newPri);
- } else _PR_SetThreadPriority(thread, newPri);
+ } else {
+ _PR_SetThreadPriority(thread, newPri);
+ }
}
PR_IMPLEMENT(PRStatus) PR_SetCurrentThreadName(const char *name)
@@ -1595,14 +1635,16 @@ PR_IMPLEMENT(PRStatus) PR_SetCurrentThreadName(const char *name)
}
thread = PR_GetCurrentThread();
- if (!thread)
+ if (!thread) {
return PR_FAILURE;
+ }
PR_Free(thread->name);
nameLen = strlen(name);
thread->name = (char *)PR_Malloc(nameLen + 1);
- if (!thread->name)
+ if (!thread->name) {
return PR_FAILURE;
+ }
memcpy(thread->name, name, nameLen + 1);
_PR_MD_SET_CURRENT_THREAD_NAME(thread->name);
return PR_SUCCESS;
@@ -1610,14 +1652,15 @@ PR_IMPLEMENT(PRStatus) PR_SetCurrentThreadName(const char *name)
PR_IMPLEMENT(const char *) PR_GetThreadName(const PRThread *thread)
{
- if (!thread)
+ if (!thread) {
return NULL;
+ }
return thread->name;
}
/*
-** This routine prevents all other threads from running. This call is needed by
+** This routine prevents all other threads from running. This call is needed by
** the garbage collector.
*/
PR_IMPLEMENT(void) PR_SuspendAll(void)
@@ -1633,25 +1676,27 @@ PR_IMPLEMENT(void) PR_SuspendAll(void)
suspendAllThread = _PR_MD_CURRENT_THREAD();
_PR_MD_BEGIN_SUSPEND_ALL();
for (qp = _PR_ACTIVE_LOCAL_THREADQ().next;
- qp != &_PR_ACTIVE_LOCAL_THREADQ(); qp = qp->next) {
- if ((me != _PR_ACTIVE_THREAD_PTR(qp)) &&
+ qp != &_PR_ACTIVE_LOCAL_THREADQ(); qp = qp->next) {
+ if ((me != _PR_ACTIVE_THREAD_PTR(qp)) &&
_PR_IS_GCABLE_THREAD(_PR_ACTIVE_THREAD_PTR(qp))) {
_PR_Suspend(_PR_ACTIVE_THREAD_PTR(qp));
- PR_ASSERT((_PR_ACTIVE_THREAD_PTR(qp))->state != _PR_RUNNING);
- }
+ PR_ASSERT((_PR_ACTIVE_THREAD_PTR(qp))->state != _PR_RUNNING);
+ }
}
for (qp = _PR_ACTIVE_GLOBAL_THREADQ().next;
- qp != &_PR_ACTIVE_GLOBAL_THREADQ(); qp = qp->next) {
+ qp != &_PR_ACTIVE_GLOBAL_THREADQ(); qp = qp->next) {
if ((me != _PR_ACTIVE_THREAD_PTR(qp)) &&
_PR_IS_GCABLE_THREAD(_PR_ACTIVE_THREAD_PTR(qp)))
/* PR_Suspend(_PR_ACTIVE_THREAD_PTR(qp)); */
- _PR_MD_SUSPEND_THREAD(_PR_ACTIVE_THREAD_PTR(qp));
+ {
+ _PR_MD_SUSPEND_THREAD(_PR_ACTIVE_THREAD_PTR(qp));
+ }
}
_PR_MD_END_SUSPEND_ALL();
}
/*
-** This routine unblocks all other threads that were suspended from running by
+** This routine unblocks all other threads that were suspended from running by
** PR_SuspendAll(). This call is needed by the garbage collector.
*/
PR_IMPLEMENT(void) PR_ResumeAll(void)
@@ -1664,16 +1709,18 @@ PR_IMPLEMENT(void) PR_ResumeAll(void)
*/
_PR_MD_BEGIN_RESUME_ALL();
for (qp = _PR_ACTIVE_LOCAL_THREADQ().next;
- qp != &_PR_ACTIVE_LOCAL_THREADQ(); qp = qp->next) {
- if ((me != _PR_ACTIVE_THREAD_PTR(qp)) &&
- _PR_IS_GCABLE_THREAD(_PR_ACTIVE_THREAD_PTR(qp)))
+ qp != &_PR_ACTIVE_LOCAL_THREADQ(); qp = qp->next) {
+ if ((me != _PR_ACTIVE_THREAD_PTR(qp)) &&
+ _PR_IS_GCABLE_THREAD(_PR_ACTIVE_THREAD_PTR(qp))) {
_PR_Resume(_PR_ACTIVE_THREAD_PTR(qp));
+ }
}
for (qp = _PR_ACTIVE_GLOBAL_THREADQ().next;
- qp != &_PR_ACTIVE_GLOBAL_THREADQ(); qp = qp->next) {
+ qp != &_PR_ACTIVE_GLOBAL_THREADQ(); qp = qp->next) {
if ((me != _PR_ACTIVE_THREAD_PTR(qp)) &&
- _PR_IS_GCABLE_THREAD(_PR_ACTIVE_THREAD_PTR(qp)))
- _PR_MD_RESUME_THREAD(_PR_ACTIVE_THREAD_PTR(qp));
+ _PR_IS_GCABLE_THREAD(_PR_ACTIVE_THREAD_PTR(qp))) {
+ _PR_MD_RESUME_THREAD(_PR_ACTIVE_THREAD_PTR(qp));
+ }
}
_PR_MD_END_RESUME_ALL();
suspendAllThread = NULL;
@@ -1715,8 +1762,9 @@ PR_IMPLEMENT(PRStatus) PR_EnumerateThreads(PREnumerator func, void *arg)
if (_PR_IS_GCABLE_THREAD(t))
{
rv = (*func)(t, i, arg);
- if (rv != PR_SUCCESS)
+ if (rv != PR_SUCCESS) {
return rv;
+ }
i++;
}
}
@@ -1728,8 +1776,9 @@ PR_IMPLEMENT(PRStatus) PR_EnumerateThreads(PREnumerator func, void *arg)
if (_PR_IS_GCABLE_THREAD(t))
{
rv = (*func)(t, i, arg);
- if (rv != PR_SUCCESS)
+ if (rv != PR_SUCCESS) {
return rv;
+ }
i++;
}
}
@@ -1787,7 +1836,7 @@ _PR_AddSleepQ(PRThread *thread, PRIntervalTime timeout)
** must be one) so that they remain relative to us.
*/
PR_ASSERT (thread->links.next != &_PR_SLEEPQ(cpu));
-
+
t = _PR_THREAD_PTR(thread->links.next);
PR_ASSERT(_PR_THREAD_PTR(t->links.prev) == thread);
t->sleep -= sleep;
@@ -1821,24 +1870,28 @@ _PR_DelSleepQ(PRThread *thread, PRBool propogate_time)
if (propogate_time == PR_TRUE) {
PRThread *after = _PR_THREAD_PTR(q);
after->sleep += thread->sleep;
- } else
+ } else {
_PR_SLEEPQMAX(cpu) -= thread->sleep;
+ }
} else {
/* Check if prev is the beggining of the list; if so,
- * we are the only element on the list.
+ * we are the only element on the list.
*/
- if (thread->links.prev != &_PR_SLEEPQ(cpu))
+ if (thread->links.prev != &_PR_SLEEPQ(cpu)) {
_PR_SLEEPQMAX(cpu) -= thread->sleep;
- else
+ }
+ else {
_PR_SLEEPQMAX(cpu) = 0;
+ }
}
thread->flags &= ~_PR_ON_SLEEPQ;
} else {
thread->flags &= ~_PR_ON_PAUSEQ;
}
PR_REMOVE_LINK(&thread->links);
- } else
+ } else {
PR_ASSERT(0);
+ }
}
void
@@ -1861,17 +1914,17 @@ _PR_AddThreadToRunQ(
* "post" the awakened thread to the IO completion port
* for the next idle CPU to execute (this is done in
* _PR_MD_WAKEUP_WAITER).
- * Threads with a suspended I/O operation remain bound to
- * the same cpu until I/O is cancelled
+ * Threads with a suspended I/O operation remain bound to
+ * the same cpu until I/O is cancelled
*
* NOTE: the boolean expression below must be the exact
* opposite of the corresponding boolean expression in
* _PR_MD_WAKEUP_WAITER.
*/
if ((!_PR_IS_NATIVE_THREAD(me) && (cpu == me->cpu)) ||
- (thread->md.thr_bound_cpu)) {
- PR_ASSERT(!thread->md.thr_bound_cpu ||
- (thread->md.thr_bound_cpu == cpu));
+ (thread->md.thr_bound_cpu)) {
+ PR_ASSERT(!thread->md.thr_bound_cpu ||
+ (thread->md.thr_bound_cpu == cpu));
_PR_RUNQ_LOCK(cpu);
_PR_ADD_RUNQ(thread, cpu, pri);
_PR_RUNQ_UNLOCK(cpu);
diff --git a/nsprpub/pr/src/threads/prcmon.c b/nsprpub/pr/src/threads/prcmon.c
index 2a196e9d4..c1d354ced 100644
--- a/nsprpub/pr/src/threads/prcmon.c
+++ b/nsprpub/pr/src/threads/prcmon.c
@@ -100,9 +100,11 @@ static PRStatus ExpandMonitorCache(PRUintn new_size_log2)
** Expand the monitor-cache-entry free list
*/
new_block = (MonitorCacheEntryBlock*)
- PR_CALLOC(sizeof(MonitorCacheEntryBlock)
- + (entries - 1) * sizeof(MonitorCacheEntry));
- if (NULL == new_block) return PR_FAILURE;
+ PR_CALLOC(sizeof(MonitorCacheEntryBlock)
+ + (entries - 1) * sizeof(MonitorCacheEntry));
+ if (NULL == new_block) {
+ return PR_FAILURE;
+ }
/*
** Allocate system monitors for the new monitor cache entries. If we
@@ -110,8 +112,9 @@ static PRStatus ExpandMonitorCache(PRUintn new_size_log2)
*/
for (i = 0, p = new_block->entries; i < entries; i++, p++) {
p->mon = PR_NewMonitor();
- if (!p->mon)
+ if (!p->mon) {
break;
+ }
}
added = i;
if (added != entries) {
@@ -129,10 +132,11 @@ static PRStatus ExpandMonitorCache(PRUintn new_size_log2)
** carry on with the too-large new_block.
*/
realloc_block = (MonitorCacheEntryBlock*)
- PR_REALLOC(new_block, sizeof(MonitorCacheEntryBlock)
- + (added - 1) * sizeof(MonitorCacheEntry));
- if (realloc_block)
+ PR_REALLOC(new_block, sizeof(MonitorCacheEntryBlock)
+ + (added - 1) * sizeof(MonitorCacheEntry));
+ if (realloc_block) {
new_block = realloc_block;
+ }
}
/*
@@ -141,8 +145,9 @@ static PRStatus ExpandMonitorCache(PRUintn new_size_log2)
** the mcache-lock and we aren't calling anyone who might want to use
** it.
*/
- for (i = 0, p = new_block->entries; i < added - 1; i++, p++)
+ for (i = 0, p = new_block->entries; i < added - 1; i++, p++) {
p->next = p + 1;
+ }
p->next = free_entries;
free_entries = new_block->entries;
num_free_entries += added;
@@ -151,7 +156,7 @@ static PRStatus ExpandMonitorCache(PRUintn new_size_log2)
/* Try to expand the hash table */
new_hash_buckets = (MonitorCacheEntry**)
- PR_CALLOC(entries * sizeof(MonitorCacheEntry*));
+ PR_CALLOC(entries * sizeof(MonitorCacheEntry*));
if (NULL == new_hash_buckets) {
/*
** Partial lossage. In this situation we don't get any more hash
@@ -220,8 +225,9 @@ static MonitorCacheEntry **LookupMonitorCacheEntry(void *address)
pp = hash_buckets + hash;
while ((p = *pp) != 0) {
if (p->address == address) {
- if (p->cacheEntryCount > 0)
+ if (p->cacheEntryCount > 0) {
return pp;
+ }
return NULL;
}
pp = &p->next;
@@ -242,7 +248,9 @@ static PRMonitor *CreateMonitor(void *address)
hash = HASH(address);
pp = hash_buckets + hash;
while ((p = *pp) != 0) {
- if (p->address == address) goto gotit;
+ if (p->address == address) {
+ goto gotit;
+ }
pp = &p->next;
}
@@ -261,7 +269,9 @@ static PRMonitor *CreateMonitor(void *address)
expanding = PR_TRUE;
rv = ExpandMonitorCache(num_hash_buckets_log2 + 1);
expanding = PR_FALSE;
- if (PR_FAILURE == rv) return NULL;
+ if (PR_FAILURE == rv) {
+ return NULL;
+ }
/* redo the hash because it'll be different now */
hash = HASH(address);
@@ -278,14 +288,15 @@ static PRMonitor *CreateMonitor(void *address)
p = free_entries;
free_entries = p->next;
num_free_entries--;
- if (OnMonitorRecycle && p->address)
+ if (OnMonitorRecycle && p->address) {
OnMonitorRecycle(p->address);
+ }
p->address = address;
p->next = hash_buckets[hash];
hash_buckets[hash] = p;
PR_ASSERT(p->cacheEntryCount == 0);
- gotit:
+gotit:
p->cacheEntryCount++;
return p->mon;
}
@@ -337,13 +348,17 @@ PR_IMPLEMENT(PRMonitor*) PR_CEnterMonitor(void *address)
{
PRMonitor *mon;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
_PR_LOCK_MCACHE();
mon = CreateMonitor(address);
_PR_UNLOCK_MCACHE();
- if (!mon) return NULL;
+ if (!mon) {
+ return NULL;
+ }
PR_EnterMonitor(mon);
return mon;
@@ -389,8 +404,9 @@ PR_IMPLEMENT(PRStatus) PR_CWait(void *address, PRIntervalTime ticks)
mon = pp ? ((*pp)->mon) : NULL;
_PR_UNLOCK_MCACHE();
- if (mon == NULL)
+ if (mon == NULL) {
return PR_FAILURE;
+ }
return PR_Wait(mon, ticks);
}
@@ -404,8 +420,9 @@ PR_IMPLEMENT(PRStatus) PR_CNotify(void *address)
mon = pp ? ((*pp)->mon) : NULL;
_PR_UNLOCK_MCACHE();
- if (mon == NULL)
+ if (mon == NULL) {
return PR_FAILURE;
+ }
return PR_Notify(mon);
}
@@ -419,8 +436,9 @@ PR_IMPLEMENT(PRStatus) PR_CNotifyAll(void *address)
mon = pp ? ((*pp)->mon) : NULL;
_PR_UNLOCK_MCACHE();
- if (mon == NULL)
+ if (mon == NULL) {
return PR_FAILURE;
+ }
return PR_NotifyAll(mon);
}
diff --git a/nsprpub/pr/src/threads/prcthr.c b/nsprpub/pr/src/threads/prcthr.c
index 268814473..e7044ed53 100644
--- a/nsprpub/pr/src/threads/prcthr.c
+++ b/nsprpub/pr/src/threads/prcthr.c
@@ -7,17 +7,17 @@
#if defined(WIN95)
/*
-** Some local variables report warnings on Win95 because the code paths
+** Some local variables report warnings on Win95 because the code paths
** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
** The pragma suppresses the warning.
-**
+**
*/
#pragma warning(disable : 4101)
#endif
extern PRLock *_pr_sleeplock; /* allocated and initialized in prinit */
-/*
+/*
** Routines common to both native and user threads.
**
**
@@ -46,7 +46,7 @@ PR_IMPLEMENT(PRStatus) PR_Yield()
{
static PRBool warning = PR_TRUE;
if (warning) warning = _PR_Obsolete(
- "PR_Yield()", "PR_Sleep(PR_INTERVAL_NO_WAIT)");
+ "PR_Yield()", "PR_Sleep(PR_INTERVAL_NO_WAIT)");
return (PR_Sleep(PR_INTERVAL_NO_WAIT));
}
@@ -64,7 +64,9 @@ PR_IMPLEMENT(PRStatus) PR_Sleep(PRIntervalTime timeout)
{
PRStatus rv = PR_SUCCESS;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if (PR_INTERVAL_NO_WAIT == timeout)
{
@@ -76,7 +78,9 @@ PR_IMPLEMENT(PRStatus) PR_Sleep(PRIntervalTime timeout)
PRUintn pri = me->priority;
_PRCPU *cpu = _PR_MD_CURRENT_CPU();
- if ( _PR_IS_NATIVE_THREAD(me) ) _PR_MD_YIELD();
+ if ( _PR_IS_NATIVE_THREAD(me) ) {
+ _PR_MD_YIELD();
+ }
else
{
_PR_INTSOFF(is);
@@ -118,7 +122,9 @@ PR_IMPLEMENT(PRStatus) PR_Sleep(PRIntervalTime timeout)
do
{
PRIntervalTime delta = PR_IntervalNow() - timein;
- if (delta > timeout) break;
+ if (delta > timeout) {
+ break;
+ }
rv = PR_WaitCondVar(cv, timeout - delta);
} while (rv == PR_SUCCESS);
PR_Unlock(_pr_sleeplock);
@@ -139,7 +145,9 @@ PR_IMPLEMENT(PRThreadPriority) PR_GetThreadPriority(const PRThread *thread)
PR_IMPLEMENT(PRThread *) PR_GetCurrentThread()
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
return _PR_MD_CURRENT_THREAD();
}
@@ -161,52 +169,60 @@ PR_IMPLEMENT(PRStatus) PR_Interrupt(PRThread *thread)
if ((NULL != victim) && (!(thread->flags & _PR_INTERRUPT_BLOCKED))) {
int haveLock = (victim->lock->owner == _PR_MD_CURRENT_THREAD());
- if (!haveLock) PR_Lock(victim->lock);
+ if (!haveLock) {
+ PR_Lock(victim->lock);
+ }
PR_NotifyAllCondVar(victim);
- if (!haveLock) PR_Unlock(victim->lock);
+ if (!haveLock) {
+ PR_Unlock(victim->lock);
+ }
}
return PR_SUCCESS;
#else /* ! _PR_GLOBAL_THREADS_ONLY */
PRIntn is;
PRThread *me = _PR_MD_CURRENT_THREAD();
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
-
- _PR_THREAD_LOCK(thread);
- thread->flags |= _PR_INTERRUPT;
- switch (thread->state) {
- case _PR_COND_WAIT:
- /*
- * call is made with thread locked;
- * on return lock is released
- */
- if (!(thread->flags & _PR_INTERRUPT_BLOCKED))
- _PR_NotifyLockedThread(thread);
- break;
- case _PR_IO_WAIT:
- /*
- * Need to hold the thread lock when calling
- * _PR_Unblock_IO_Wait(). On return lock is
- * released.
- */
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
+
+ _PR_THREAD_LOCK(thread);
+ thread->flags |= _PR_INTERRUPT;
+ switch (thread->state) {
+ case _PR_COND_WAIT:
+ /*
+ * call is made with thread locked;
+ * on return lock is released
+ */
+ if (!(thread->flags & _PR_INTERRUPT_BLOCKED)) {
+ _PR_NotifyLockedThread(thread);
+ }
+ break;
+ case _PR_IO_WAIT:
+ /*
+ * Need to hold the thread lock when calling
+ * _PR_Unblock_IO_Wait(). On return lock is
+ * released.
+ */
#if defined(XP_UNIX) || defined(WINNT) || defined(WIN16)
- if (!(thread->flags & _PR_INTERRUPT_BLOCKED))
- _PR_Unblock_IO_Wait(thread);
+ if (!(thread->flags & _PR_INTERRUPT_BLOCKED)) {
+ _PR_Unblock_IO_Wait(thread);
+ }
#else
- _PR_THREAD_UNLOCK(thread);
+ _PR_THREAD_UNLOCK(thread);
#endif
- break;
- case _PR_RUNNING:
- case _PR_RUNNABLE:
- case _PR_LOCK_WAIT:
- default:
- _PR_THREAD_UNLOCK(thread);
- break;
- }
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSON(is);
- return PR_SUCCESS;
+ break;
+ case _PR_RUNNING:
+ case _PR_RUNNABLE:
+ case _PR_LOCK_WAIT:
+ default:
+ _PR_THREAD_UNLOCK(thread);
+ break;
+ }
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
+ return PR_SUCCESS;
#endif /* _PR_GLOBAL_THREADS_ONLY */
}
@@ -218,11 +234,15 @@ PR_IMPLEMENT(void) PR_ClearInterrupt()
PRIntn is;
PRThread *me = _PR_MD_CURRENT_THREAD();
- if ( !_PR_IS_NATIVE_THREAD(me)) _PR_INTSOFF(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_THREAD_LOCK(me);
- me->flags &= ~_PR_INTERRUPT;
+ me->flags &= ~_PR_INTERRUPT;
_PR_THREAD_UNLOCK(me);
- if ( !_PR_IS_NATIVE_THREAD(me)) _PR_INTSON(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
}
PR_IMPLEMENT(void) PR_BlockInterrupt()
@@ -230,11 +250,15 @@ PR_IMPLEMENT(void) PR_BlockInterrupt()
PRIntn is;
PRThread *me = _PR_MD_CURRENT_THREAD();
- if ( !_PR_IS_NATIVE_THREAD(me)) _PR_INTSOFF(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_THREAD_LOCK(me);
_PR_THREAD_BLOCK_INTERRUPT(me);
_PR_THREAD_UNLOCK(me);
- if ( !_PR_IS_NATIVE_THREAD(me)) _PR_INTSON(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
} /* PR_BlockInterrupt */
PR_IMPLEMENT(void) PR_UnblockInterrupt()
@@ -242,11 +266,15 @@ PR_IMPLEMENT(void) PR_UnblockInterrupt()
PRIntn is;
PRThread *me = _PR_MD_CURRENT_THREAD();
- if ( !_PR_IS_NATIVE_THREAD(me)) _PR_INTSOFF(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_THREAD_LOCK(me);
_PR_THREAD_UNBLOCK_INTERRUPT(me);
_PR_THREAD_UNLOCK(me);
- if ( !_PR_IS_NATIVE_THREAD(me)) _PR_INTSON(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
} /* PR_UnblockInterrupt */
/*
@@ -254,17 +282,17 @@ PR_IMPLEMENT(void) PR_UnblockInterrupt()
*/
PR_IMPLEMENT(void *) PR_GetSP(PRThread *thread)
{
- return (void *)_PR_MD_GET_SP(thread);
+ return (void *)_PR_MD_GET_SP(thread);
}
PR_IMPLEMENT(void*) GetExecutionEnvironment(PRThread *thread)
{
- return thread->environment;
+ return thread->environment;
}
PR_IMPLEMENT(void) SetExecutionEnvironment(PRThread *thread, void *env)
{
- thread->environment = env;
+ thread->environment = env;
}
@@ -280,12 +308,8 @@ PR_IMPLEMENT(PRInt32) PR_GetThreadAffinityMask(PRThread *thread, PRUint32 *mask)
PR_IMPLEMENT(PRInt32) PR_SetThreadAffinityMask(PRThread *thread, PRUint32 mask )
{
#ifdef HAVE_THREAD_AFFINITY
-#ifndef IRIX
return _PR_MD_SETTHREADAFFINITYMASK(thread, mask);
#else
- return 0;
-#endif
-#else
return 0;
#endif
}
@@ -298,7 +322,9 @@ PR_IMPLEMENT(PRInt32) PR_SetCPUAffinityMask(PRUint32 mask)
PRCList *qp;
extern PRUint32 _pr_cpu_affinity_mask;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
_pr_cpu_affinity_mask = mask;
@@ -323,27 +349,27 @@ PR_IMPLEMENT(void) PR_SetThreadRecycleMode(PRUint32 count)
}
PR_IMPLEMENT(PRThread*) PR_CreateThreadGCAble(PRThreadType type,
- void (*start)(void *arg),
- void *arg,
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+ void (*start)(void *arg),
+ void *arg,
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize)
{
- return _PR_CreateThread(type, start, arg, priority, scope, state,
+ return _PR_CreateThread(type, start, arg, priority, scope, state,
stackSize, _PR_GCABLE_THREAD);
}
#ifdef SOLARIS
PR_IMPLEMENT(PRThread*) PR_CreateThreadBound(PRThreadType type,
- void (*start)(void *arg),
- void *arg,
- PRUintn priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+ void (*start)(void *arg),
+ void *arg,
+ PRUintn priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize)
{
- return _PR_CreateThread(type, start, arg, priority, scope, state,
+ return _PR_CreateThread(type, start, arg, priority, scope, state,
stackSize, _PR_BOUND_THREAD);
}
#endif
@@ -359,29 +385,36 @@ PR_IMPLEMENT(PRThread*) PR_AttachThreadGCAble(
PR_IMPLEMENT(void) PR_SetThreadGCAble()
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
PR_Lock(_pr_activeLock);
- _PR_MD_CURRENT_THREAD()->flags |= _PR_GCABLE_THREAD;
- PR_Unlock(_pr_activeLock);
+ _PR_MD_CURRENT_THREAD()->flags |= _PR_GCABLE_THREAD;
+ PR_Unlock(_pr_activeLock);
}
PR_IMPLEMENT(void) PR_ClearThreadGCAble()
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
PR_Lock(_pr_activeLock);
- _PR_MD_CURRENT_THREAD()->flags &= (~_PR_GCABLE_THREAD);
- PR_Unlock(_pr_activeLock);
+ _PR_MD_CURRENT_THREAD()->flags &= (~_PR_GCABLE_THREAD);
+ PR_Unlock(_pr_activeLock);
}
PR_IMPLEMENT(PRThreadScope) PR_GetThreadScope(const PRThread *thread)
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if (_PR_IS_NATIVE_THREAD(thread)) {
- return (thread->flags & _PR_BOUND_THREAD) ? PR_GLOBAL_BOUND_THREAD :
- PR_GLOBAL_THREAD;
- } else
+ return (thread->flags & _PR_BOUND_THREAD) ? PR_GLOBAL_BOUND_THREAD :
+ PR_GLOBAL_THREAD;
+ } else {
return PR_LOCAL_THREAD;
+ }
}
PR_IMPLEMENT(PRThreadType) PR_GetThreadType(const PRThread *thread)
diff --git a/nsprpub/pr/src/threads/prdump.c b/nsprpub/pr/src/threads/prdump.c
index b40bee30c..04d842047 100644
--- a/nsprpub/pr/src/threads/prdump.c
+++ b/nsprpub/pr/src/threads/prdump.c
@@ -7,10 +7,10 @@
#if defined(WIN95)
/*
-** Some local variables report warnings on Win95 because the code paths
+** Some local variables report warnings on Win95 because the code paths
** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
** The pragma suppresses the warning.
-**
+**
*/
#pragma warning(disable : 4101)
#endif
@@ -40,26 +40,26 @@ void _PR_DumpThread(PRFileDesc *fd, PRThread *thread)
_PR_DumpPrintf(fd, "%05d[%08p] pri=%2d flags=0x%02x",
thread->id, thread, thread->priority, thread->flags);
switch (thread->state) {
- case _PR_RUNNABLE:
- case _PR_RUNNING:
- break;
- case _PR_LOCK_WAIT:
- _PR_DumpPrintf(fd, " lock=%p", thread->wait.lock);
- break;
- case _PR_COND_WAIT:
- _PR_DumpPrintf(fd, " condvar=%p sleep=%lldms",
- thread->wait.cvar, thread->sleep);
- break;
- case _PR_SUSPENDED:
- _PR_DumpPrintf(fd, " suspended");
- break;
+ case _PR_RUNNABLE:
+ case _PR_RUNNING:
+ break;
+ case _PR_LOCK_WAIT:
+ _PR_DumpPrintf(fd, " lock=%p", thread->wait.lock);
+ break;
+ case _PR_COND_WAIT:
+ _PR_DumpPrintf(fd, " condvar=%p sleep=%lldms",
+ thread->wait.cvar, thread->sleep);
+ break;
+ case _PR_SUSPENDED:
+ _PR_DumpPrintf(fd, " suspended");
+ break;
}
PR_Write(fd, "\n", 1);
#endif
/* Now call dump routine */
if (thread->dump) {
- thread->dump(fd, thread, thread->dumpArg);
+ thread->dump(fd, thread, thread->dumpArg);
}
}
@@ -106,11 +106,15 @@ PR_IMPLEMENT(void) PR_ShowStatus(void)
PRIntn is;
if ( _PR_MD_CURRENT_THREAD()
- && !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) _PR_INTSOFF(is);
+ && !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) {
+ _PR_INTSOFF(is);
+ }
_pr_dumpOut = _pr_stderr;
_PR_DumpThreads(_pr_dumpOut);
if ( _PR_MD_CURRENT_THREAD()
- && !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) _PR_FAST_INTSON(is);
+ && !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) {
+ _PR_FAST_INTSON(is);
+ }
}
PR_IMPLEMENT(void)
diff --git a/nsprpub/pr/src/threads/prmon.c b/nsprpub/pr/src/threads/prmon.c
index 36be8a941..b7c526eea 100644
--- a/nsprpub/pr/src/threads/prmon.c
+++ b/nsprpub/pr/src/threads/prmon.c
@@ -20,10 +20,12 @@ static void _PR_PostNotifyToMonitor(PRMonitor *mon, PRBool broadcast)
/* mon->notifyTimes is protected by the monitor, so we don't need to
* acquire mon->lock.
*/
- if (broadcast)
+ if (broadcast) {
mon->notifyTimes = -1;
- else if (mon->notifyTimes != -1)
+ }
+ else if (mon->notifyTimes != -1) {
mon->notifyTimes += 1;
+ }
}
static void _PR_PostNotifiesFromMonitor(PRCondVar *cv, PRIntn times)
@@ -55,7 +57,9 @@ PR_IMPLEMENT(PRMonitor*) PR_NewMonitor()
PRMonitor *mon;
PRStatus rv;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
mon = PR_NEWZAP(PRMonitor);
if (mon == NULL) {
@@ -65,20 +69,23 @@ PR_IMPLEMENT(PRMonitor*) PR_NewMonitor()
rv = _PR_InitLock(&mon->lock);
PR_ASSERT(rv == PR_SUCCESS);
- if (rv != PR_SUCCESS)
+ if (rv != PR_SUCCESS) {
goto error1;
+ }
mon->owner = NULL;
rv = _PR_InitCondVar(&mon->entryCV, &mon->lock);
PR_ASSERT(rv == PR_SUCCESS);
- if (rv != PR_SUCCESS)
+ if (rv != PR_SUCCESS) {
goto error2;
+ }
rv = _PR_InitCondVar(&mon->waitCV, &mon->lock);
PR_ASSERT(rv == PR_SUCCESS);
- if (rv != PR_SUCCESS)
+ if (rv != PR_SUCCESS) {
goto error3;
+ }
mon->notifyTimes = 0;
mon->entryCount = 0;
@@ -97,8 +104,9 @@ error1:
PR_IMPLEMENT(PRMonitor*) PR_NewNamedMonitor(const char* name)
{
PRMonitor* mon = PR_NewMonitor();
- if (mon)
+ if (mon) {
mon->name = name;
+ }
return mon;
}
@@ -130,8 +138,9 @@ PR_IMPLEMENT(void) PR_EnterMonitor(PRMonitor *mon)
PR_ASSERT(mon != NULL);
PR_Lock(&mon->lock);
if (mon->entryCount != 0) {
- if (mon->owner == me)
+ if (mon->owner == me) {
goto done;
+ }
while (mon->entryCount != 0) {
rv = PR_WaitCondVar(&mon->entryCV, PR_INTERVAL_NO_TIMEOUT);
PR_ASSERT(rv == PR_SUCCESS);
@@ -161,8 +170,9 @@ PR_IMPLEMENT(PRBool) PR_TestAndEnterMonitor(PRMonitor *mon)
PR_ASSERT(mon != NULL);
PR_Lock(&mon->lock);
if (mon->entryCount != 0) {
- if (mon->owner == me)
+ if (mon->owner == me) {
goto done;
+ }
rv = PR_Unlock(&mon->lock);
PR_ASSERT(rv == PR_SUCCESS);
return PR_FALSE;
@@ -228,8 +238,9 @@ PR_IMPLEMENT(PRIntn) PR_GetMonitorEntryCount(PRMonitor *mon)
PRIntn count = 0;
PR_Lock(&mon->lock);
- if (mon->owner == me)
+ if (mon->owner == me) {
count = mon->entryCount;
+ }
rv = PR_Unlock(&mon->lock);
PR_ASSERT(rv == PR_SUCCESS);
return count;
@@ -337,10 +348,10 @@ PRUint32 _PR_MonitorToString(PRMonitor *mon, char *buf, PRUint32 buflen)
PRUint32 nb;
if (mon->owner) {
- nb = PR_snprintf(buf, buflen, "[%p] owner=%d[%p] count=%ld",
- mon, mon->owner->id, mon->owner, mon->entryCount);
+ nb = PR_snprintf(buf, buflen, "[%p] owner=%d[%p] count=%ld",
+ mon, mon->owner->id, mon->owner, mon->entryCount);
} else {
- nb = PR_snprintf(buf, buflen, "[%p]", mon);
+ nb = PR_snprintf(buf, buflen, "[%p]", mon);
}
return nb;
}
diff --git a/nsprpub/pr/src/threads/prrwlock.c b/nsprpub/pr/src/threads/prrwlock.c
index 1dd9e0a90..0cb51e5bd 100644
--- a/nsprpub/pr/src/threads/prrwlock.c
+++ b/nsprpub/pr/src/threads/prrwlock.c
@@ -36,43 +36,43 @@
* Reader-writer lock
*/
struct PRRWLock {
- char *rw_name; /* lock name */
- PRUint32 rw_rank; /* rank of the lock */
+ char *rw_name; /* lock name */
+ PRUint32 rw_rank; /* rank of the lock */
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
- RWLOCK_T rw_lock;
+ RWLOCK_T rw_lock;
#else
- PRLock *rw_lock;
- PRInt32 rw_lock_cnt; /* == 0, if unlocked */
- /* == -1, if write-locked */
- /* > 0 , # of read locks */
- PRUint32 rw_reader_cnt; /* number of waiting readers */
- PRUint32 rw_writer_cnt; /* number of waiting writers */
- PRCondVar *rw_reader_waitq; /* cvar for readers */
- PRCondVar *rw_writer_waitq; /* cvar for writers */
+ PRLock *rw_lock;
+ PRInt32 rw_lock_cnt; /* == 0, if unlocked */
+ /* == -1, if write-locked */
+ /* > 0 , # of read locks */
+ PRUint32 rw_reader_cnt; /* number of waiting readers */
+ PRUint32 rw_writer_cnt; /* number of waiting writers */
+ PRCondVar *rw_reader_waitq; /* cvar for readers */
+ PRCondVar *rw_writer_waitq; /* cvar for writers */
#ifdef DEBUG
- PRThread *rw_owner; /* lock owner for write-lock */
+ PRThread *rw_owner; /* lock owner for write-lock */
#endif
#endif
};
#ifdef DEBUG
-#define _PR_RWLOCK_RANK_ORDER_DEBUG /* enable deadlock detection using
- rank-order for locks
- */
+#define _PR_RWLOCK_RANK_ORDER_DEBUG /* enable deadlock detection using
+ rank-order for locks
+ */
#endif
#ifdef _PR_RWLOCK_RANK_ORDER_DEBUG
-static PRUintn pr_thread_rwlock_key; /* TPD key for lock stack */
-static PRUintn pr_thread_rwlock_alloc_failed;
+static PRUintn pr_thread_rwlock_key; /* TPD key for lock stack */
+static PRUintn pr_thread_rwlock_alloc_failed;
-#define _PR_RWLOCK_RANK_ORDER_LIMIT 10
+#define _PR_RWLOCK_RANK_ORDER_LIMIT 10
typedef struct thread_rwlock_stack {
- PRInt32 trs_index; /* top of stack */
- PRRWLock *trs_stack[_PR_RWLOCK_RANK_ORDER_LIMIT]; /* stack of lock
- pointers */
+ PRInt32 trs_index; /* top of stack */
+ PRRWLock *trs_stack[_PR_RWLOCK_RANK_ORDER_LIMIT]; /* stack of lock
+ pointers */
} thread_rwlock_stack;
@@ -89,8 +89,8 @@ static void _PR_RELEASE_LOCK_STACK(void *lock_stack);
/*
* PR_NewRWLock
- * Create a reader-writer lock, with the given lock rank and lock name
- *
+ * Create a reader-writer lock, with the given lock rank and lock name
+ *
*/
PR_IMPLEMENT(PRRWLock *)
@@ -98,64 +98,67 @@ PR_NewRWLock(PRUint32 lock_rank, const char *lock_name)
{
PRRWLock *rwlock;
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
- int err;
+ int err;
#endif
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
rwlock = PR_NEWZAP(PRRWLock);
- if (rwlock == NULL)
- return NULL;
-
- rwlock->rw_rank = lock_rank;
- if (lock_name != NULL) {
- rwlock->rw_name = (char*) PR_Malloc(strlen(lock_name) + 1);
- if (rwlock->rw_name == NULL) {
- PR_DELETE(rwlock);
- return(NULL);
- }
- strcpy(rwlock->rw_name, lock_name);
- } else {
- rwlock->rw_name = NULL;
- }
-
+ if (rwlock == NULL) {
+ return NULL;
+ }
+
+ rwlock->rw_rank = lock_rank;
+ if (lock_name != NULL) {
+ rwlock->rw_name = (char*) PR_Malloc(strlen(lock_name) + 1);
+ if (rwlock->rw_name == NULL) {
+ PR_DELETE(rwlock);
+ return(NULL);
+ }
+ strcpy(rwlock->rw_name, lock_name);
+ } else {
+ rwlock->rw_name = NULL;
+ }
+
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
- err = RWLOCK_INIT(&rwlock->rw_lock);
- if (err != 0) {
- PR_SetError(PR_UNKNOWN_ERROR, err);
- PR_Free(rwlock->rw_name);
- PR_DELETE(rwlock);
- return NULL;
- }
- return rwlock;
+ err = RWLOCK_INIT(&rwlock->rw_lock);
+ if (err != 0) {
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ PR_Free(rwlock->rw_name);
+ PR_DELETE(rwlock);
+ return NULL;
+ }
+ return rwlock;
#else
- rwlock->rw_lock = PR_NewLock();
+ rwlock->rw_lock = PR_NewLock();
if (rwlock->rw_lock == NULL) {
- goto failed;
- }
- rwlock->rw_reader_waitq = PR_NewCondVar(rwlock->rw_lock);
+ goto failed;
+ }
+ rwlock->rw_reader_waitq = PR_NewCondVar(rwlock->rw_lock);
if (rwlock->rw_reader_waitq == NULL) {
- goto failed;
- }
- rwlock->rw_writer_waitq = PR_NewCondVar(rwlock->rw_lock);
+ goto failed;
+ }
+ rwlock->rw_writer_waitq = PR_NewCondVar(rwlock->rw_lock);
if (rwlock->rw_writer_waitq == NULL) {
- goto failed;
- }
- rwlock->rw_reader_cnt = 0;
- rwlock->rw_writer_cnt = 0;
- rwlock->rw_lock_cnt = 0;
- return rwlock;
+ goto failed;
+ }
+ rwlock->rw_reader_cnt = 0;
+ rwlock->rw_writer_cnt = 0;
+ rwlock->rw_lock_cnt = 0;
+ return rwlock;
failed:
- if (rwlock->rw_reader_waitq != NULL) {
- PR_DestroyCondVar(rwlock->rw_reader_waitq);
- }
- if (rwlock->rw_lock != NULL) {
- PR_DestroyLock(rwlock->rw_lock);
- }
- PR_Free(rwlock->rw_name);
- PR_DELETE(rwlock);
- return NULL;
+ if (rwlock->rw_reader_waitq != NULL) {
+ PR_DestroyCondVar(rwlock->rw_reader_waitq);
+ }
+ if (rwlock->rw_lock != NULL) {
+ PR_DestroyLock(rwlock->rw_lock);
+ }
+ PR_Free(rwlock->rw_name);
+ PR_DELETE(rwlock);
+ return NULL;
#endif
}
@@ -166,17 +169,18 @@ PR_IMPLEMENT(void)
PR_DestroyRWLock(PRRWLock *rwlock)
{
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
- int err;
- err = RWLOCK_DESTROY(&rwlock->rw_lock);
- PR_ASSERT(err == 0);
+ int err;
+ err = RWLOCK_DESTROY(&rwlock->rw_lock);
+ PR_ASSERT(err == 0);
#else
- PR_ASSERT(rwlock->rw_reader_cnt == 0);
- PR_DestroyCondVar(rwlock->rw_reader_waitq);
- PR_DestroyCondVar(rwlock->rw_writer_waitq);
- PR_DestroyLock(rwlock->rw_lock);
+ PR_ASSERT(rwlock->rw_reader_cnt == 0);
+ PR_DestroyCondVar(rwlock->rw_reader_waitq);
+ PR_DestroyCondVar(rwlock->rw_writer_waitq);
+ PR_DestroyLock(rwlock->rw_lock);
#endif
- if (rwlock->rw_name != NULL)
- PR_Free(rwlock->rw_name);
+ if (rwlock->rw_name != NULL) {
+ PR_Free(rwlock->rw_name);
+ }
PR_DELETE(rwlock);
}
@@ -187,47 +191,48 @@ PR_IMPLEMENT(void)
PR_RWLock_Rlock(PRRWLock *rwlock)
{
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
-int err;
+ int err;
#endif
#ifdef _PR_RWLOCK_RANK_ORDER_DEBUG
- /*
- * assert that rank ordering is not violated; the rank of 'rwlock' should
- * be equal to or greater than the highest rank of all the locks held by
- * the thread.
- */
- PR_ASSERT((rwlock->rw_rank == PR_RWLOCK_RANK_NONE) ||
- (rwlock->rw_rank >= _PR_GET_THREAD_RWLOCK_RANK()));
+ /*
+ * assert that rank ordering is not violated; the rank of 'rwlock' should
+ * be equal to or greater than the highest rank of all the locks held by
+ * the thread.
+ */
+ PR_ASSERT((rwlock->rw_rank == PR_RWLOCK_RANK_NONE) ||
+ (rwlock->rw_rank >= _PR_GET_THREAD_RWLOCK_RANK()));
#endif
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
- err = RWLOCK_RDLOCK(&rwlock->rw_lock);
- PR_ASSERT(err == 0);
+ err = RWLOCK_RDLOCK(&rwlock->rw_lock);
+ PR_ASSERT(err == 0);
#else
- PR_Lock(rwlock->rw_lock);
- /*
- * wait if write-locked or if a writer is waiting; preference for writers
- */
- while ((rwlock->rw_lock_cnt < 0) ||
- (rwlock->rw_writer_cnt > 0)) {
- rwlock->rw_reader_cnt++;
- PR_WaitCondVar(rwlock->rw_reader_waitq, PR_INTERVAL_NO_TIMEOUT);
- rwlock->rw_reader_cnt--;
- }
- /*
- * Increment read-lock count
- */
- rwlock->rw_lock_cnt++;
-
- PR_Unlock(rwlock->rw_lock);
+ PR_Lock(rwlock->rw_lock);
+ /*
+ * wait if write-locked or if a writer is waiting; preference for writers
+ */
+ while ((rwlock->rw_lock_cnt < 0) ||
+ (rwlock->rw_writer_cnt > 0)) {
+ rwlock->rw_reader_cnt++;
+ PR_WaitCondVar(rwlock->rw_reader_waitq, PR_INTERVAL_NO_TIMEOUT);
+ rwlock->rw_reader_cnt--;
+ }
+ /*
+ * Increment read-lock count
+ */
+ rwlock->rw_lock_cnt++;
+
+ PR_Unlock(rwlock->rw_lock);
#endif
#ifdef _PR_RWLOCK_RANK_ORDER_DEBUG
- /*
- * update thread's lock rank
- */
- if (rwlock->rw_rank != PR_RWLOCK_RANK_NONE)
- _PR_SET_THREAD_RWLOCK_RANK(rwlock);
+ /*
+ * update thread's lock rank
+ */
+ if (rwlock->rw_rank != PR_RWLOCK_RANK_NONE) {
+ _PR_SET_THREAD_RWLOCK_RANK(rwlock);
+ }
#endif
}
@@ -238,53 +243,54 @@ PR_IMPLEMENT(void)
PR_RWLock_Wlock(PRRWLock *rwlock)
{
#if defined(DEBUG)
-PRThread *me = PR_GetCurrentThread();
+ PRThread *me = PR_GetCurrentThread();
#endif
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
-int err;
+ int err;
#endif
#ifdef _PR_RWLOCK_RANK_ORDER_DEBUG
- /*
- * assert that rank ordering is not violated; the rank of 'rwlock' should
- * be equal to or greater than the highest rank of all the locks held by
- * the thread.
- */
- PR_ASSERT((rwlock->rw_rank == PR_RWLOCK_RANK_NONE) ||
- (rwlock->rw_rank >= _PR_GET_THREAD_RWLOCK_RANK()));
+ /*
+ * assert that rank ordering is not violated; the rank of 'rwlock' should
+ * be equal to or greater than the highest rank of all the locks held by
+ * the thread.
+ */
+ PR_ASSERT((rwlock->rw_rank == PR_RWLOCK_RANK_NONE) ||
+ (rwlock->rw_rank >= _PR_GET_THREAD_RWLOCK_RANK()));
#endif
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
- err = RWLOCK_WRLOCK(&rwlock->rw_lock);
- PR_ASSERT(err == 0);
+ err = RWLOCK_WRLOCK(&rwlock->rw_lock);
+ PR_ASSERT(err == 0);
#else
- PR_Lock(rwlock->rw_lock);
- /*
- * wait if read locked
- */
- while (rwlock->rw_lock_cnt != 0) {
- rwlock->rw_writer_cnt++;
- PR_WaitCondVar(rwlock->rw_writer_waitq, PR_INTERVAL_NO_TIMEOUT);
- rwlock->rw_writer_cnt--;
- }
- /*
- * apply write lock
- */
- rwlock->rw_lock_cnt--;
- PR_ASSERT(rwlock->rw_lock_cnt == -1);
+ PR_Lock(rwlock->rw_lock);
+ /*
+ * wait if read locked
+ */
+ while (rwlock->rw_lock_cnt != 0) {
+ rwlock->rw_writer_cnt++;
+ PR_WaitCondVar(rwlock->rw_writer_waitq, PR_INTERVAL_NO_TIMEOUT);
+ rwlock->rw_writer_cnt--;
+ }
+ /*
+ * apply write lock
+ */
+ rwlock->rw_lock_cnt--;
+ PR_ASSERT(rwlock->rw_lock_cnt == -1);
#ifdef DEBUG
- PR_ASSERT(me != NULL);
- rwlock->rw_owner = me;
+ PR_ASSERT(me != NULL);
+ rwlock->rw_owner = me;
#endif
- PR_Unlock(rwlock->rw_lock);
+ PR_Unlock(rwlock->rw_lock);
#endif
#ifdef _PR_RWLOCK_RANK_ORDER_DEBUG
- /*
- * update thread's lock rank
- */
- if (rwlock->rw_rank != PR_RWLOCK_RANK_NONE)
- _PR_SET_THREAD_RWLOCK_RANK(rwlock);
+ /*
+ * update thread's lock rank
+ */
+ if (rwlock->rw_rank != PR_RWLOCK_RANK_NONE) {
+ _PR_SET_THREAD_RWLOCK_RANK(rwlock);
+ }
#endif
}
@@ -295,64 +301,68 @@ PR_IMPLEMENT(void)
PR_RWLock_Unlock(PRRWLock *rwlock)
{
#if defined(DEBUG)
-PRThread *me = PR_GetCurrentThread();
+ PRThread *me = PR_GetCurrentThread();
#endif
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
-int err;
+ int err;
#endif
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
- err = RWLOCK_UNLOCK(&rwlock->rw_lock);
- PR_ASSERT(err == 0);
+ err = RWLOCK_UNLOCK(&rwlock->rw_lock);
+ PR_ASSERT(err == 0);
#else
- PR_Lock(rwlock->rw_lock);
- /*
- * lock must be read or write-locked
- */
- PR_ASSERT(rwlock->rw_lock_cnt != 0);
- if (rwlock->rw_lock_cnt > 0) {
-
- /*
- * decrement read-lock count
- */
- rwlock->rw_lock_cnt--;
- if (rwlock->rw_lock_cnt == 0) {
- /*
- * lock is not read-locked anymore; wakeup a waiting writer
- */
- if (rwlock->rw_writer_cnt > 0)
- PR_NotifyCondVar(rwlock->rw_writer_waitq);
- }
- } else {
- PR_ASSERT(rwlock->rw_lock_cnt == -1);
-
- rwlock->rw_lock_cnt = 0;
+ PR_Lock(rwlock->rw_lock);
+ /*
+ * lock must be read or write-locked
+ */
+ PR_ASSERT(rwlock->rw_lock_cnt != 0);
+ if (rwlock->rw_lock_cnt > 0) {
+
+ /*
+ * decrement read-lock count
+ */
+ rwlock->rw_lock_cnt--;
+ if (rwlock->rw_lock_cnt == 0) {
+ /*
+ * lock is not read-locked anymore; wakeup a waiting writer
+ */
+ if (rwlock->rw_writer_cnt > 0) {
+ PR_NotifyCondVar(rwlock->rw_writer_waitq);
+ }
+ }
+ } else {
+ PR_ASSERT(rwlock->rw_lock_cnt == -1);
+
+ rwlock->rw_lock_cnt = 0;
#ifdef DEBUG
- PR_ASSERT(rwlock->rw_owner == me);
- rwlock->rw_owner = NULL;
+ PR_ASSERT(rwlock->rw_owner == me);
+ rwlock->rw_owner = NULL;
#endif
- /*
- * wakeup a writer, if present; preference for writers
- */
- if (rwlock->rw_writer_cnt > 0)
- PR_NotifyCondVar(rwlock->rw_writer_waitq);
- /*
- * else, wakeup all readers, if any
- */
- else if (rwlock->rw_reader_cnt > 0)
- PR_NotifyAllCondVar(rwlock->rw_reader_waitq);
- }
- PR_Unlock(rwlock->rw_lock);
+ /*
+ * wakeup a writer, if present; preference for writers
+ */
+ if (rwlock->rw_writer_cnt > 0) {
+ PR_NotifyCondVar(rwlock->rw_writer_waitq);
+ }
+ /*
+ * else, wakeup all readers, if any
+ */
+ else if (rwlock->rw_reader_cnt > 0) {
+ PR_NotifyAllCondVar(rwlock->rw_reader_waitq);
+ }
+ }
+ PR_Unlock(rwlock->rw_lock);
#endif
#ifdef _PR_RWLOCK_RANK_ORDER_DEBUG
- /*
- * update thread's lock rank
- */
- if (rwlock->rw_rank != PR_RWLOCK_RANK_NONE)
- _PR_UNSET_THREAD_RWLOCK_RANK(rwlock);
+ /*
+ * update thread's lock rank
+ */
+ if (rwlock->rw_rank != PR_RWLOCK_RANK_NONE) {
+ _PR_UNSET_THREAD_RWLOCK_RANK(rwlock);
+ }
#endif
- return;
+ return;
}
#ifndef _PR_RWLOCK_RANK_ORDER_DEBUG
@@ -363,121 +373,126 @@ void _PR_InitRWLocks(void) { }
void _PR_InitRWLocks(void)
{
- /*
- * allocated thread-private-data index for rwlock list
- */
- if (PR_NewThreadPrivateIndex(&pr_thread_rwlock_key,
- _PR_RELEASE_LOCK_STACK) == PR_FAILURE) {
- pr_thread_rwlock_alloc_failed = 1;
- return;
- }
+ /*
+ * allocated thread-private-data index for rwlock list
+ */
+ if (PR_NewThreadPrivateIndex(&pr_thread_rwlock_key,
+ _PR_RELEASE_LOCK_STACK) == PR_FAILURE) {
+ pr_thread_rwlock_alloc_failed = 1;
+ return;
+ }
}
/*
* _PR_SET_THREAD_RWLOCK_RANK
- * Set a thread's lock rank, which is the highest of the ranks of all
- * the locks held by the thread. Pointers to the locks are added to a
- * per-thread list, which is anchored off a thread-private data key.
+ * Set a thread's lock rank, which is the highest of the ranks of all
+ * the locks held by the thread. Pointers to the locks are added to a
+ * per-thread list, which is anchored off a thread-private data key.
*/
static void
_PR_SET_THREAD_RWLOCK_RANK(PRRWLock *rwlock)
{
-thread_rwlock_stack *lock_stack;
-PRStatus rv;
-
- /*
- * allocate a lock stack
- */
- if ((lock_stack = PR_GetThreadPrivate(pr_thread_rwlock_key)) == NULL) {
- lock_stack = (thread_rwlock_stack *)
- PR_CALLOC(1 * sizeof(thread_rwlock_stack));
- if (lock_stack) {
- rv = PR_SetThreadPrivate(pr_thread_rwlock_key, lock_stack);
- if (rv == PR_FAILURE) {
- PR_DELETE(lock_stack);
- pr_thread_rwlock_alloc_failed = 1;
- return;
- }
- } else {
- pr_thread_rwlock_alloc_failed = 1;
- return;
- }
- }
- /*
- * add rwlock to lock stack, if limit is not exceeded
- */
- if (lock_stack) {
- if (lock_stack->trs_index < _PR_RWLOCK_RANK_ORDER_LIMIT)
- lock_stack->trs_stack[lock_stack->trs_index++] = rwlock;
- }
+ thread_rwlock_stack *lock_stack;
+ PRStatus rv;
+
+ /*
+ * allocate a lock stack
+ */
+ if ((lock_stack = PR_GetThreadPrivate(pr_thread_rwlock_key)) == NULL) {
+ lock_stack = (thread_rwlock_stack *)
+ PR_CALLOC(1 * sizeof(thread_rwlock_stack));
+ if (lock_stack) {
+ rv = PR_SetThreadPrivate(pr_thread_rwlock_key, lock_stack);
+ if (rv == PR_FAILURE) {
+ PR_DELETE(lock_stack);
+ pr_thread_rwlock_alloc_failed = 1;
+ return;
+ }
+ } else {
+ pr_thread_rwlock_alloc_failed = 1;
+ return;
+ }
+ }
+ /*
+ * add rwlock to lock stack, if limit is not exceeded
+ */
+ if (lock_stack) {
+ if (lock_stack->trs_index < _PR_RWLOCK_RANK_ORDER_LIMIT) {
+ lock_stack->trs_stack[lock_stack->trs_index++] = rwlock;
+ }
+ }
}
static void
_PR_RELEASE_LOCK_STACK(void *lock_stack)
{
- PR_ASSERT(lock_stack);
- PR_DELETE(lock_stack);
+ PR_ASSERT(lock_stack);
+ PR_DELETE(lock_stack);
}
/*
* _PR_GET_THREAD_RWLOCK_RANK
*
- * return thread's lock rank. If thread-private-data for the lock
- * stack is not allocated, return PR_RWLOCK_RANK_NONE.
+ * return thread's lock rank. If thread-private-data for the lock
+ * stack is not allocated, return PR_RWLOCK_RANK_NONE.
*/
-
+
static PRUint32
_PR_GET_THREAD_RWLOCK_RANK(void)
{
- thread_rwlock_stack *lock_stack;
-
- lock_stack = PR_GetThreadPrivate(pr_thread_rwlock_key);
- if (lock_stack == NULL || lock_stack->trs_index == 0)
- return (PR_RWLOCK_RANK_NONE);
- else
- return(lock_stack->trs_stack[lock_stack->trs_index - 1]->rw_rank);
+ thread_rwlock_stack *lock_stack;
+
+ lock_stack = PR_GetThreadPrivate(pr_thread_rwlock_key);
+ if (lock_stack == NULL || lock_stack->trs_index == 0) {
+ return (PR_RWLOCK_RANK_NONE);
+ }
+ else {
+ return(lock_stack->trs_stack[lock_stack->trs_index - 1]->rw_rank);
+ }
}
/*
* _PR_UNSET_THREAD_RWLOCK_RANK
*
- * remove the rwlock from the lock stack. Since locks may not be
- * unlocked in a FIFO order, the entire lock stack is searched.
+ * remove the rwlock from the lock stack. Since locks may not be
+ * unlocked in a FIFO order, the entire lock stack is searched.
*/
-
+
static void
_PR_UNSET_THREAD_RWLOCK_RANK(PRRWLock *rwlock)
{
- thread_rwlock_stack *lock_stack;
- int new_index = 0, index, done = 0;
-
- lock_stack = PR_GetThreadPrivate(pr_thread_rwlock_key);
-
- PR_ASSERT(lock_stack != NULL);
-
- for (index = lock_stack->trs_index - 1; index >= 0; index--) {
- if (!done && (lock_stack->trs_stack[index] == rwlock)) {
- /*
- * reset the slot for rwlock
- */
- lock_stack->trs_stack[index] = NULL;
- done = 1;
- }
- /*
- * search for the lowest-numbered empty slot, above which there are
- * no non-empty slots
- */
- if (!new_index && (lock_stack->trs_stack[index] != NULL))
- new_index = index + 1;
- if (done && new_index)
- break;
- }
- /*
- * set top of stack to highest numbered empty slot
- */
- lock_stack->trs_index = new_index;
+ thread_rwlock_stack *lock_stack;
+ int new_index = 0, index, done = 0;
+
+ lock_stack = PR_GetThreadPrivate(pr_thread_rwlock_key);
+
+ PR_ASSERT(lock_stack != NULL);
+
+ for (index = lock_stack->trs_index - 1; index >= 0; index--) {
+ if (!done && (lock_stack->trs_stack[index] == rwlock)) {
+ /*
+ * reset the slot for rwlock
+ */
+ lock_stack->trs_stack[index] = NULL;
+ done = 1;
+ }
+ /*
+ * search for the lowest-numbered empty slot, above which there are
+ * no non-empty slots
+ */
+ if (!new_index && (lock_stack->trs_stack[index] != NULL)) {
+ new_index = index + 1;
+ }
+ if (done && new_index) {
+ break;
+ }
+ }
+ /*
+ * set top of stack to highest numbered empty slot
+ */
+ lock_stack->trs_index = new_index;
}
-#endif /* _PR_RWLOCK_RANK_ORDER_DEBUG */
+#endif /* _PR_RWLOCK_RANK_ORDER_DEBUG */
diff --git a/nsprpub/pr/src/threads/prsem.c b/nsprpub/pr/src/threads/prsem.c
index f5f261fe9..120075b0c 100644
--- a/nsprpub/pr/src/threads/prsem.c
+++ b/nsprpub/pr/src/threads/prsem.c
@@ -26,16 +26,16 @@ PR_IMPLEMENT(PRSemaphore*) PR_NewSem(PRUintn value)
if (!lock) {
PR_DELETE(sem);
return NULL;
- }
+ }
cvar = PR_NewCondVar(lock);
if (!cvar) {
PR_DestroyLock(lock);
PR_DELETE(sem);
return NULL;
- }
- sem->cvar = cvar;
- sem->count = value;
+ }
+ sem->cvar = cvar;
+ sem->count = value;
#endif
}
return sem;
@@ -61,56 +61,59 @@ PR_IMPLEMENT(void) PR_DestroySem(PRSemaphore *sem)
/*
** Wait on a Semaphore.
-**
-** This routine allows a calling thread to wait or proceed depending upon the
-** state of the semahore sem. The thread can proceed only if the counter value
-** of the semaphore sem is currently greater than 0. If the value of semaphore
-** sem is positive, it is decremented by one and the routine returns immediately
-** allowing the calling thread to continue. If the value of semaphore sem is 0,
-** the calling thread blocks awaiting the semaphore to be released by another
+**
+** This routine allows a calling thread to wait or proceed depending upon the
+** state of the semahore sem. The thread can proceed only if the counter value
+** of the semaphore sem is currently greater than 0. If the value of semaphore
+** sem is positive, it is decremented by one and the routine returns immediately
+** allowing the calling thread to continue. If the value of semaphore sem is 0,
+** the calling thread blocks awaiting the semaphore to be released by another
** thread.
-**
-** This routine can return PR_PENDING_INTERRUPT if the waiting thread
+**
+** This routine can return PR_PENDING_INTERRUPT if the waiting thread
** has been interrupted.
*/
PR_IMPLEMENT(PRStatus) PR_WaitSem(PRSemaphore *sem)
{
- PRStatus status = PR_SUCCESS;
+ PRStatus status = PR_SUCCESS;
#ifdef HAVE_CVAR_BUILT_ON_SEM
- return _PR_MD_WAIT_SEM(&sem->md);
+ return _PR_MD_WAIT_SEM(&sem->md);
#else
- PR_Lock(sem->cvar->lock);
- while (sem->count == 0) {
- sem->waiters++;
- status = PR_WaitCondVar(sem->cvar, PR_INTERVAL_NO_TIMEOUT);
- sem->waiters--;
- if (status != PR_SUCCESS)
- break;
- }
- if (status == PR_SUCCESS)
- sem->count--;
- PR_Unlock(sem->cvar->lock);
+ PR_Lock(sem->cvar->lock);
+ while (sem->count == 0) {
+ sem->waiters++;
+ status = PR_WaitCondVar(sem->cvar, PR_INTERVAL_NO_TIMEOUT);
+ sem->waiters--;
+ if (status != PR_SUCCESS) {
+ break;
+ }
+ }
+ if (status == PR_SUCCESS) {
+ sem->count--;
+ }
+ PR_Unlock(sem->cvar->lock);
#endif
-
- return (status);
+
+ return (status);
}
/*
-** This routine increments the counter value of the semaphore. If other threads
-** are blocked for the semaphore, then the scheduler will determine which ONE
+** This routine increments the counter value of the semaphore. If other threads
+** are blocked for the semaphore, then the scheduler will determine which ONE
** thread will be unblocked.
*/
PR_IMPLEMENT(void) PR_PostSem(PRSemaphore *sem)
{
#ifdef HAVE_CVAR_BUILT_ON_SEM
- _PR_MD_POST_SEM(&sem->md);
+ _PR_MD_POST_SEM(&sem->md);
#else
- PR_Lock(sem->cvar->lock);
- if (sem->waiters)
- PR_NotifyCondVar(sem->cvar);
- sem->count++;
- PR_Unlock(sem->cvar->lock);
+ PR_Lock(sem->cvar->lock);
+ if (sem->waiters) {
+ PR_NotifyCondVar(sem->cvar);
+ }
+ sem->count++;
+ PR_Unlock(sem->cvar->lock);
#endif
}
@@ -123,16 +126,16 @@ PR_IMPLEMENT(void) PR_PostSem(PRSemaphore *sem)
*/
PR_IMPLEMENT(PRUintn) PR_GetValueSem(PRSemaphore *sem)
{
- PRUintn rv;
+ PRUintn rv;
#ifdef HAVE_CVAR_BUILT_ON_SEM
- rv = _PR_MD_GET_VALUE_SEM(&sem->md);
+ rv = _PR_MD_GET_VALUE_SEM(&sem->md);
#else
- PR_Lock(sem->cvar->lock);
- rv = sem->count;
- PR_Unlock(sem->cvar->lock);
+ PR_Lock(sem->cvar->lock);
+ rv = sem->count;
+ PR_Unlock(sem->cvar->lock);
#endif
-
- return rv;
+
+ return rv;
}
#endif
diff --git a/nsprpub/pr/src/threads/prtpd.c b/nsprpub/pr/src/threads/prtpd.c
index 0eb2a011c..e6385cf70 100644
--- a/nsprpub/pr/src/threads/prtpd.c
+++ b/nsprpub/pr/src/threads/prtpd.c
@@ -32,7 +32,6 @@
** the routines in pr/src/btthreads/
*/
-#ifndef XP_BEOS
#include "primpl.h"
@@ -40,10 +39,10 @@
#if defined(WIN95)
/*
-** Some local variables report warnings on Win95 because the code paths
+** Some local variables report warnings on Win95 because the code paths
** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
** The pragma suppresses the warning.
-**
+**
*/
#pragma warning(disable : 4101)
#endif
@@ -52,9 +51,9 @@
static PRInt32 _pr_tpd_length = 0; /* current length of destructor vector */
static PRInt32 _pr_tpd_highwater = 0; /* next TPD key to be assigned */
static PRThreadPrivateDTOR *_pr_tpd_destructors = NULL;
- /* the destructors are associated with
- the keys, therefore asserting that
- the TPD key depicts the data's 'type' */
+/* the destructors are associated with
+ the keys, therefore asserting that
+ the TPD key depicts the data's 'type' */
/*
** Initialize the thread private data manipulation
@@ -62,7 +61,7 @@ static PRThreadPrivateDTOR *_pr_tpd_destructors = NULL;
void _PR_InitTPD(void)
{
_pr_tpd_destructors = (PRThreadPrivateDTOR*)
- PR_CALLOC(_PR_TPD_LIMIT * sizeof(PRThreadPrivateDTOR*));
+ PR_CALLOC(_PR_TPD_LIMIT * sizeof(PRThreadPrivateDTOR*));
PR_ASSERT(NULL != _pr_tpd_destructors);
_pr_tpd_length = _PR_TPD_LIMIT;
}
@@ -75,22 +74,22 @@ void _PR_CleanupTPD(void)
} /* _PR_CleanupTPD */
/*
-** This routine returns a new index for per-thread-private data table.
-** The index is visible to all threads within a process. This index can
-** be used with the PR_SetThreadPrivate() and PR_GetThreadPrivate() routines
+** This routine returns a new index for per-thread-private data table.
+** The index is visible to all threads within a process. This index can
+** be used with the PR_SetThreadPrivate() and PR_GetThreadPrivate() routines
** to save and retrieve data associated with the index for a thread.
**
-** The index independently maintains specific values for each binding thread.
+** The index independently maintains specific values for each binding thread.
** A thread can only get access to its own thread-specific-data.
**
** Upon a new index return the value associated with the index for all threads
-** is NULL, and upon thread creation the value associated with all indices for
-** that thread is NULL.
+** is NULL, and upon thread creation the value associated with all indices for
+** that thread is NULL.
**
** "dtor" is the destructor function to invoke when the private
** data is set or destroyed
**
-** Returns PR_FAILURE if the total number of indices will exceed the maximun
+** Returns PR_FAILURE if the total number of indices will exceed the maximun
** allowed.
*/
@@ -100,7 +99,9 @@ PR_IMPLEMENT(PRStatus) PR_NewThreadPrivateIndex(
PRStatus rv;
PRInt32 index;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
PR_ASSERT(NULL != newIndex);
PR_ASSERT(NULL != _pr_tpd_destructors);
@@ -124,7 +125,7 @@ PR_IMPLEMENT(PRStatus) PR_NewThreadPrivateIndex(
/*
** Define some per-thread-private data.
** "index" is an index into the per-thread private data table
-** "priv" is the per-thread-private data
+** "priv" is the per-thread-private data
**
** If the per-thread private data table has a previously registered
** destructor function and a non-NULL per-thread-private data value,
@@ -150,7 +151,7 @@ PR_IMPLEMENT(PRStatus) PR_SetThreadPrivate(PRUintn index, void *priv)
}
PR_ASSERT(((NULL == self->privateData) && (0 == self->tpdLength))
- || ((NULL != self->privateData) && (0 != self->tpdLength)));
+ || ((NULL != self->privateData) && (0 != self->tpdLength)));
/*
** If this thread does not have a sufficient vector for the index
@@ -192,9 +193,9 @@ PR_IMPLEMENT(PRStatus) PR_SetThreadPrivate(PRUintn index, void *priv)
/*
** Recover the per-thread-private data for the current thread. "index" is
-** the index into the per-thread private data table.
+** the index into the per-thread private data table.
**
-** The returned value may be NULL which is indistinguishable from an error
+** The returned value may be NULL which is indistinguishable from an error
** condition.
**
*/
@@ -203,7 +204,7 @@ PR_IMPLEMENT(void*) PR_GetThreadPrivate(PRUintn index)
{
PRThread *self = PR_GetCurrentThread();
void *tpd = ((NULL == self->privateData) || (index >= self->tpdLength)) ?
- NULL : self->privateData[index];
+ NULL : self->privateData[index];
return tpd;
}
@@ -249,4 +250,3 @@ void _PR_DestroyThreadPrivate(PRThread* self)
}
} /* _PR_DestroyThreadPrivate */
-#endif /* !XP_BEOS */