diff options
Diffstat (limited to 'nsprpub/pr/src/md/os2/os2cv.c')
-rw-r--r-- | nsprpub/pr/src/md/os2/os2cv.c | 96 |
1 files changed, 50 insertions, 46 deletions
diff --git a/nsprpub/pr/src/md/os2/os2cv.c b/nsprpub/pr/src/md/os2/os2cv.c index 2c424c50b0..91e85c0ebd 100644 --- a/nsprpub/pr/src/md/os2/os2cv.c +++ b/nsprpub/pr/src/md/os2/os2cv.c @@ -16,7 +16,7 @@ * until right after we unlock the lock. This way the awakened threads * have a better chance to reaquire the lock. */ - + #include "primpl.h" /* @@ -30,7 +30,7 @@ static void AddThreadToCVWaitQueueInternal(PRThread *thred, struct _MDCVar *cv) { PR_ASSERT((cv->waitTail != NULL && cv->waitHead != NULL) - || (cv->waitTail == NULL && cv->waitHead == NULL)); + || (cv->waitTail == NULL && cv->waitHead == NULL)); cv->nwait += 1; thred->md.inCVWaitQueue = PR_TRUE; thred->md.next = NULL; @@ -78,7 +78,7 @@ md_UnlockAndPostNotifies( lock->notified.link = NULL; #endif - /* + /* * Figure out how many threads we need to wake up. */ notified = &post; /* this is where we start */ @@ -87,7 +87,7 @@ md_UnlockAndPostNotifies( _MDCVar *cv = notified->cv[index].cv; PRThread *thred; int i; - + /* Fast special case: no waiting threads */ if (cv->waitHead == NULL) { notified->cv[index].notifyHead = NULL; @@ -155,7 +155,9 @@ md_UnlockAndPostNotifies( } prev = notified; notified = notified->link; - if (&post != prev) PR_DELETE(prev); + if (&post != prev) { + PR_DELETE(prev); + } } while (NULL != notified); } @@ -165,7 +167,7 @@ md_UnlockAndPostNotifies( * MP systems don't contend for a lock that they can't have. */ static void md_PostNotifyToCvar(_MDCVar *cvar, _MDLock *lock, - PRBool broadcast) + PRBool broadcast) { PRIntn index = 0; _MDNotified *notified = &lock->notified; @@ -182,7 +184,9 @@ static void md_PostNotifyToCvar(_MDCVar *cvar, _MDLock *lock, } } /* if not full, enter new CV in this array */ - if (notified->length < _MD_CV_NOTIFIED_LENGTH) break; + if (notified->length < _MD_CV_NOTIFIED_LENGTH) { + break; + } /* if there's no link, create an empty array and link it */ if (NULL == notified->link) { @@ -215,7 +219,7 @@ _PR_MD_NEW_CV(_MDCVar *cv) * when the PRCondVar structure is created. */ return 0; -} +} void _PR_MD_FREE_CV(_MDCVar *cv) { @@ -232,7 +236,7 @@ _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout ) PRThread *thred = _PR_MD_CURRENT_THREAD(); ULONG rv, count; ULONG msecs = (timeout == PR_INTERVAL_NO_TIMEOUT) ? - SEM_INDEFINITE_WAIT : PR_IntervalToMilliseconds(timeout); + SEM_INDEFINITE_WAIT : PR_IntervalToMilliseconds(timeout); /* * If we have pending notifies, post them now. @@ -241,7 +245,7 @@ _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout ) md_UnlockAndPostNotifies(lock, thred, cv); } else { AddThreadToCVWaitQueueInternal(thred, cv); - DosReleaseMutexSem(lock->mutex); + DosReleaseMutexSem(lock->mutex); } /* Wait for notification or timeout; don't really care which */ @@ -256,42 +260,42 @@ _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout ) if(rv == ERROR_TIMEOUT) { - if (thred->md.inCVWaitQueue) { - PR_ASSERT((cv->waitTail != NULL && cv->waitHead != NULL) - || (cv->waitTail == NULL && cv->waitHead == NULL)); - cv->nwait -= 1; - thred->md.inCVWaitQueue = PR_FALSE; - if (cv->waitHead == thred) { - cv->waitHead = thred->md.next; - if (cv->waitHead == NULL) { - cv->waitTail = NULL; - } else { - cv->waitHead->md.prev = NULL; - } - } else { - PR_ASSERT(thred->md.prev != NULL); - thred->md.prev->md.next = thred->md.next; - if (thred->md.next != NULL) { - thred->md.next->md.prev = thred->md.prev; - } else { - PR_ASSERT(cv->waitTail == thred); - cv->waitTail = thred->md.prev; - } - } - thred->md.next = thred->md.prev = NULL; - } else { - /* - * This thread must have been notified, but the - * SemRelease call happens after SemRequest - * times out. Wait on the semaphore again to make it - * non-signaled. We assume this wait won't take long. - */ - rv = DosWaitEventSem(thred->md.blocked_sema, SEM_INDEFINITE_WAIT); - if (rv == NO_ERROR) { - DosResetEventSem(thred->md.blocked_sema, &count); - } - PR_ASSERT(rv == NO_ERROR); - } + if (thred->md.inCVWaitQueue) { + PR_ASSERT((cv->waitTail != NULL && cv->waitHead != NULL) + || (cv->waitTail == NULL && cv->waitHead == NULL)); + cv->nwait -= 1; + thred->md.inCVWaitQueue = PR_FALSE; + if (cv->waitHead == thred) { + cv->waitHead = thred->md.next; + if (cv->waitHead == NULL) { + cv->waitTail = NULL; + } else { + cv->waitHead->md.prev = NULL; + } + } else { + PR_ASSERT(thred->md.prev != NULL); + thred->md.prev->md.next = thred->md.next; + if (thred->md.next != NULL) { + thred->md.next->md.prev = thred->md.prev; + } else { + PR_ASSERT(cv->waitTail == thred); + cv->waitTail = thred->md.prev; + } + } + thred->md.next = thred->md.prev = NULL; + } else { + /* + * This thread must have been notified, but the + * SemRelease call happens after SemRequest + * times out. Wait on the semaphore again to make it + * non-signaled. We assume this wait won't take long. + */ + rv = DosWaitEventSem(thred->md.blocked_sema, SEM_INDEFINITE_WAIT); + if (rv == NO_ERROR) { + DosResetEventSem(thred->md.blocked_sema, &count); + } + PR_ASSERT(rv == NO_ERROR); + } } PR_ASSERT(thred->md.inCVWaitQueue == PR_FALSE); return; |