summaryrefslogtreecommitdiffstats
path: root/nsprpub/pr/src/threads/prsem.c
diff options
context:
space:
mode:
Diffstat (limited to 'nsprpub/pr/src/threads/prsem.c')
-rw-r--r--nsprpub/pr/src/threads/prsem.c89
1 files changed, 46 insertions, 43 deletions
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