summaryrefslogtreecommitdiffstats
path: root/nsprpub/pr/src/io/prmwait.c
diff options
context:
space:
mode:
Diffstat (limited to 'nsprpub/pr/src/io/prmwait.c')
-rw-r--r--nsprpub/pr/src/io/prmwait.c267
1 files changed, 172 insertions, 95 deletions
diff --git a/nsprpub/pr/src/io/prmwait.c b/nsprpub/pr/src/io/prmwait.c
index ab32fb5d8..62e35ab6f 100644
--- a/nsprpub/pr/src/io/prmwait.c
+++ b/nsprpub/pr/src/io/prmwait.c
@@ -37,7 +37,7 @@ struct {
static PRStatus TimerInit(void);
static void TimerManager(void *arg);
static TimerEvent *CreateTimer(PRIntervalTime timeout,
- void (*func)(void *), void *arg);
+ void (*func)(void *), void *arg);
static PRBool CancelTimer(TimerEvent *timer);
static void TimerManager(void *arg)
@@ -81,7 +81,7 @@ static void TimerManager(void *arg)
{
timeout = (PRIntervalTime)(timer->absolute - now);
PR_WaitCondVar(tm_vars.new_timer, timeout);
- }
+ }
}
}
PR_Unlock(tm_vars.ml);
@@ -143,7 +143,7 @@ static PRBool CancelTimer(TimerEvent *timer)
}
PR_Unlock(tm_vars.ml);
PR_DELETE(timer);
- return canceled;
+ return canceled;
}
static PRStatus TimerInit(void)
@@ -165,8 +165,8 @@ static PRStatus TimerInit(void)
}
PR_INIT_CLIST(&tm_vars.timer_queue);
tm_vars.manager_thread = PR_CreateThread(
- PR_SYSTEM_THREAD, TimerManager, NULL, PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
+ PR_SYSTEM_THREAD, TimerManager, NULL, PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
if (NULL == tm_vars.manager_thread)
{
goto failed;
@@ -231,7 +231,9 @@ static PRWaitGroup *MW_Init2(void)
if (NULL == group) /* there is this special case */
{
group = PR_CreateWaitGroup(_PR_DEFAULT_HASH_LENGTH);
- if (NULL == group) goto failed_alloc;
+ if (NULL == group) {
+ goto failed_alloc;
+ }
PR_Lock(mw_lock);
if (NULL == mw_state->group)
{
@@ -239,7 +241,9 @@ static PRWaitGroup *MW_Init2(void)
group = NULL;
}
PR_Unlock(mw_lock);
- if (group != NULL) (void)PR_DestroyWaitGroup(group);
+ if (group != NULL) {
+ (void)PR_DestroyWaitGroup(group);
+ }
group = mw_state->group; /* somebody beat us to it */
}
failed_alloc:
@@ -301,7 +305,7 @@ static _PR_HashStory MW_AddHashInternal(PRRecvWait *desc, _PRWaiterHash *hash)
}
hidx = (hidx + hoffset) % (hash->length);
}
- return _prmw_rehash;
+ return _prmw_rehash;
} /* MW_AddHashInternal */
static _PR_HashStory MW_ExpandHashInternal(PRWaitGroup *group)
@@ -314,7 +318,8 @@ static _PR_HashStory MW_ExpandHashInternal(PRWaitGroup *group)
static const PRInt32 prime_number[] = {
_PR_DEFAULT_HASH_LENGTH, 179, 521, 907, 1427,
- 2711, 3917, 5021, 8219, 11549, 18911, 26711, 33749, 44771};
+ 2711, 3917, 5021, 8219, 11549, 18911, 26711, 33749, 44771
+ };
PRUintn primes = (sizeof(prime_number) / sizeof(PRInt32));
/* look up the next size we'd like to use for the hash table */
@@ -337,7 +342,7 @@ static _PR_HashStory MW_ExpandHashInternal(PRWaitGroup *group)
/* allocate the new hash table and fill it in with the old */
newHash = (_PRWaiterHash*)PR_CALLOC(
- sizeof(_PRWaiterHash) + (length * sizeof(PRRecvWait*)));
+ sizeof(_PRWaiterHash) + (length * sizeof(PRRecvWait*)));
if (NULL == newHash)
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
@@ -347,7 +352,7 @@ static _PR_HashStory MW_ExpandHashInternal(PRWaitGroup *group)
newHash->length = length;
retry = PR_FALSE;
for (desc = &oldHash->recv_wait;
- newHash->count < oldHash->count; ++desc)
+ newHash->count < oldHash->count; ++desc)
{
PR_ASSERT(desc < &oldHash->recv_wait + oldHash->length);
if (NULL != *desc)
@@ -362,7 +367,9 @@ static _PR_HashStory MW_ExpandHashInternal(PRWaitGroup *group)
}
}
}
- if (retry) continue;
+ if (retry) {
+ continue;
+ }
PR_DELETE(group->waiter);
group->waiter = newHash;
@@ -408,11 +415,13 @@ static PRRecvWait **_MW_LookupInternal(PRWaitGroup *group, PRFileDesc *fd)
_PRWaiterHash *hash = group->waiter;
PRUintn hidx = _MW_HASH(fd, hash->length);
PRUintn hoffset = 0;
-
+
while (rehash-- > 0)
{
desc = (&hash->recv_wait) + hidx;
- if ((*desc != NULL) && ((*desc)->fd == fd)) return desc;
+ if ((*desc != NULL) && ((*desc)->fd == fd)) {
+ return desc;
+ }
if (0 == hoffset)
{
hoffset = _MW_HASH2(fd, hash->length);
@@ -447,7 +456,9 @@ static PRStatus _MW_PollInternal(PRWaitGroup *group)
PR_SetError(PR_INVALID_STATE_ERROR, 0);
goto aborted;
}
- if (_MW_ABORTED(st)) goto aborted;
+ if (_MW_ABORTED(st)) {
+ goto aborted;
+ }
}
/*
@@ -470,8 +481,9 @@ static PRStatus _MW_PollInternal(PRWaitGroup *group)
PR_Lock(group->ml);
goto failed_alloc;
}
- if (NULL != old_polling_list)
+ if (NULL != old_polling_list) {
PR_DELETE(old_polling_list);
+ }
PR_Lock(group->ml);
if (_prmw_running != group->state)
{
@@ -492,22 +504,24 @@ static PRStatus _MW_PollInternal(PRWaitGroup *group)
for (count = 0; count < group->waiter->count; ++waiter)
{
PR_ASSERT(waiter < &group->waiter->recv_wait
- + group->waiter->length);
+ + group->waiter->length);
if (NULL != *waiter) /* a live one! */
{
if ((PR_INTERVAL_NO_TIMEOUT != (*waiter)->timeout)
- && (since_last_poll >= (*waiter)->timeout))
+ && (since_last_poll >= (*waiter)->timeout)) {
_MW_DoneInternal(group, waiter, PR_MW_TIMEOUT);
+ }
else
{
if (PR_INTERVAL_NO_TIMEOUT != (*waiter)->timeout)
{
(*waiter)->timeout -= since_last_poll;
- if ((*waiter)->timeout < polling_interval)
+ if ((*waiter)->timeout < polling_interval) {
polling_interval = (*waiter)->timeout;
+ }
}
PR_ASSERT(poll_list < group->polling_list
- + group->polling_count);
+ + group->polling_count);
poll_list->fd = (*waiter)->fd;
poll_list->in_flags = PR_POLL_READ;
poll_list->out_flags = 0;
@@ -520,7 +534,7 @@ static PRStatus _MW_PollInternal(PRWaitGroup *group)
count += 1;
}
}
- }
+ }
PR_ASSERT(count == group->waiter->count);
@@ -529,9 +543,13 @@ static PRStatus _MW_PollInternal(PRWaitGroup *group)
** we need to return.
*/
if ((!PR_CLIST_IS_EMPTY(&group->io_ready))
- && (1 == group->waiting_threads)) break;
+ && (1 == group->waiting_threads)) {
+ break;
+ }
- if (0 == count) continue; /* wait for new business */
+ if (0 == count) {
+ continue; /* wait for new business */
+ }
group->last_poll = now;
@@ -553,7 +571,7 @@ static PRStatus _MW_PollInternal(PRWaitGroup *group)
else if (0 < count_ready)
{
for (poll_list = group->polling_list; count > 0;
- poll_list++, count--)
+ poll_list++, count--)
{
PR_ASSERT(
poll_list < group->polling_list + group->polling_count);
@@ -564,8 +582,9 @@ static PRStatus _MW_PollInternal(PRWaitGroup *group)
** If 'waiter' is NULL, that means the wait receive
** descriptor has been canceled.
*/
- if (NULL != waiter)
+ if (NULL != waiter) {
_MW_DoneInternal(group, waiter, PR_MW_SUCCESS);
+ }
}
}
}
@@ -576,7 +595,9 @@ static PRStatus _MW_PollInternal(PRWaitGroup *group)
** belongs to the client.
*/
if ((!PR_CLIST_IS_EMPTY(&group->io_ready))
- && (1 == group->waiting_threads)) break;
+ && (1 == group->waiting_threads)) {
+ break;
+ }
}
rv = PR_SUCCESS;
@@ -604,7 +625,7 @@ static PRMWGroupState MW_TestForShutdownInternal(PRWaitGroup *group)
** to make sure no more threads are made to wait.
*/
if ((_prmw_stopping == rv)
- && (0 == group->waiting_threads))
+ && (0 == group->waiting_threads))
{
rv = group->state = _prmw_stopped;
PR_NotifyCondVar(group->mw_manage);
@@ -617,15 +638,17 @@ static void _MW_InitialRecv(PRCList *io_ready)
{
PRRecvWait *desc = (PRRecvWait*)io_ready;
if ((NULL == desc->buffer.start)
- || (0 == desc->buffer.length))
+ || (0 == desc->buffer.length)) {
desc->bytesRecv = 0;
+ }
else
{
desc->bytesRecv = (desc->fd->methods->recv)(
- desc->fd, desc->buffer.start,
- desc->buffer.length, 0, desc->timeout);
- if (desc->bytesRecv < 0) /* SetError should already be there */
+ desc->fd, desc->buffer.start,
+ desc->buffer.length, 0, desc->timeout);
+ if (desc->bytesRecv < 0) { /* SetError should already be there */
desc->outcome = PR_MW_FAILURE;
+ }
}
} /* _MW_InitialRecv */
#endif
@@ -636,9 +659,9 @@ static void NT_TimeProc(void *arg)
_MDOverlapped *overlapped = (_MDOverlapped *)arg;
PRRecvWait *desc = overlapped->data.mw.desc;
PRFileDesc *bottom;
-
+
if (InterlockedCompareExchange((LONG *)&desc->outcome,
- (LONG)PR_MW_TIMEOUT, (LONG)PR_MW_PENDING) != (LONG)PR_MW_PENDING)
+ (LONG)PR_MW_TIMEOUT, (LONG)PR_MW_PENDING) != (LONG)PR_MW_PENDING)
{
/* This wait recv descriptor has already completed. */
return;
@@ -712,7 +735,9 @@ PR_IMPLEMENT(PRStatus) PR_AddWaitFileDesc(
PRFileDesc *bottom;
#endif
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if ((NULL == group) && (NULL == (group = MW_Init2())))
{
return rv;
@@ -744,15 +769,20 @@ PR_IMPLEMENT(PRStatus) PR_AddWaitFileDesc(
** of the timing interval. As long as the list doesn't go empty,
** it will maintain itself.
*/
- if (0 == group->waiter->count)
+ if (0 == group->waiter->count) {
group->last_poll = PR_IntervalNow();
+ }
do
{
hrv = MW_AddHashInternal(desc, group->waiter);
- if (_prmw_rehash != hrv) break;
+ if (_prmw_rehash != hrv) {
+ break;
+ }
hrv = MW_ExpandHashInternal(group); /* gruesome */
- if (_prmw_success != hrv) break;
+ if (_prmw_success != hrv) {
+ break;
+ }
} while (PR_TRUE);
#ifdef WINNT
@@ -777,9 +807,9 @@ PR_IMPLEMENT(PRStatus) PR_AddWaitFileDesc(
if (desc->timeout != PR_INTERVAL_NO_TIMEOUT)
{
overlapped->data.mw.timer = CreateTimer(
- desc->timeout,
- NT_TimeProc,
- overlapped);
+ desc->timeout,
+ NT_TimeProc,
+ overlapped);
if (0 == overlapped->data.mw.timer)
{
NT_HashRemove(group, desc->fd);
@@ -801,7 +831,7 @@ PR_IMPLEMENT(PRStatus) PR_AddWaitFileDesc(
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return PR_FAILURE;
}
- hFile = (HANDLE)bottom->secret->md.osfd;
+ hFile = (HANDLE)bottom->secret->md.osfd;
if (!bottom->secret->md.io_model_committed)
{
PRInt32 st;
@@ -810,16 +840,16 @@ PR_IMPLEMENT(PRStatus) PR_AddWaitFileDesc(
bottom->secret->md.io_model_committed = PR_TRUE;
}
bResult = ReadFile(hFile,
- desc->buffer.start,
- (DWORD)desc->buffer.length,
- NULL,
- &overlapped->overlapped);
+ desc->buffer.start,
+ (DWORD)desc->buffer.length,
+ NULL,
+ &overlapped->overlapped);
if (FALSE == bResult && (dwError = GetLastError()) != ERROR_IO_PENDING)
{
if (desc->timeout != PR_INTERVAL_NO_TIMEOUT)
{
if (InterlockedCompareExchange((LONG *)&desc->outcome,
- (LONG)PR_MW_FAILURE, (LONG)PR_MW_PENDING)
+ (LONG)PR_MW_FAILURE, (LONG)PR_MW_PENDING)
== (LONG)PR_MW_PENDING)
{
CancelTimer(overlapped->data.mw.timer);
@@ -840,11 +870,15 @@ PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
PRCList *io_ready = NULL;
#ifdef WINNT
PRThread *me = _PR_MD_CURRENT_THREAD();
- _MDOverlapped *overlapped;
+ _MDOverlapped *overlapped;
#endif
- if (!_pr_initialized) _PR_ImplicitInitialization();
- if ((NULL == group) && (NULL == (group = MW_Init2()))) goto failed_init;
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+ if ((NULL == group) && (NULL == (group = MW_Init2()))) {
+ goto failed_init;
+ }
PR_Lock(group->ml);
@@ -890,7 +924,7 @@ PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
PR_REMOVE_LINK(io_ready);
_PR_MD_UNLOCK(&group->mdlock);
overlapped = (_MDOverlapped *)
- ((char *)io_ready - offsetof(_MDOverlapped, data));
+ ((char *)io_ready - offsetof(_MDOverlapped, data));
io_ready = &overlapped->data.mw.desc->internal;
#else
do
@@ -915,7 +949,9 @@ PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
** The polling function should only return w/ failure or
** with some I/O ready.
*/
- if (PR_FAILURE == _MW_PollInternal(group)) goto failed_poll;
+ if (PR_FAILURE == _MW_PollInternal(group)) {
+ goto failed_poll;
+ }
}
else
{
@@ -934,7 +970,7 @@ PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
** it is still full of if's with continue and goto.
*/
PRStatus st;
- do
+ do
{
st = PR_WaitCondVar(group->io_complete, PR_INTERVAL_NO_TIMEOUT);
if (_prmw_running != group->state)
@@ -942,7 +978,9 @@ PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
PR_SetError(PR_INVALID_STATE_ERROR, 0);
goto aborted;
}
- if (_MW_ABORTED(st) || (NULL == group->poller)) break;
+ if (_MW_ABORTED(st) || (NULL == group->poller)) {
+ break;
+ }
} while (PR_CLIST_IS_EMPTY(&group->io_ready));
/*
@@ -954,9 +992,10 @@ PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
if (_MW_ABORTED(st))
{
if ((NULL == group->poller
- || !PR_CLIST_IS_EMPTY(&group->io_ready))
- && group->waiting_threads > 1)
+ || !PR_CLIST_IS_EMPTY(&group->io_ready))
+ && group->waiting_threads > 1) {
PR_NotifyCondVar(group->io_complete);
+ }
goto aborted;
}
@@ -966,13 +1005,15 @@ PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
** i/o ready, it has a higher priority. I want to
** process the ready i/o first and wake up another
** thread to be the new poller.
- */
+ */
if (NULL == group->poller)
{
- if (PR_CLIST_IS_EMPTY(&group->io_ready))
+ if (PR_CLIST_IS_EMPTY(&group->io_ready)) {
continue;
- if (group->waiting_threads > 1)
+ }
+ if (group->waiting_threads > 1) {
PR_NotifyCondVar(group->io_complete);
+ }
}
}
PR_ASSERT(!PR_CLIST_IS_EMPTY(&group->io_ready));
@@ -1025,13 +1066,13 @@ failed_init:
if (NULL != overlapped->data.mw.timer)
{
PR_ASSERT(PR_INTERVAL_NO_TIMEOUT
- != overlapped->data.mw.desc->timeout);
+ != overlapped->data.mw.desc->timeout);
CancelTimer(overlapped->data.mw.timer);
}
else
{
PR_ASSERT(PR_INTERVAL_NO_TIMEOUT
- == overlapped->data.mw.desc->timeout);
+ == overlapped->data.mw.desc->timeout);
}
PR_DELETE(overlapped);
#endif
@@ -1045,7 +1086,9 @@ PR_IMPLEMENT(PRStatus) PR_CancelWaitFileDesc(PRWaitGroup *group, PRRecvWait *des
PRRecvWait **recv_wait;
#endif
PRStatus rv = PR_SUCCESS;
- if (NULL == group) group = mw_state->group;
+ if (NULL == group) {
+ group = mw_state->group;
+ }
PR_ASSERT(NULL != group);
if (NULL == group)
{
@@ -1064,7 +1107,7 @@ PR_IMPLEMENT(PRStatus) PR_CancelWaitFileDesc(PRWaitGroup *group, PRRecvWait *des
#ifdef WINNT
if (InterlockedCompareExchange((LONG *)&desc->outcome,
- (LONG)PR_MW_INTERRUPT, (LONG)PR_MW_PENDING) == (LONG)PR_MW_PENDING)
+ (LONG)PR_MW_INTERRUPT, (LONG)PR_MW_PENDING) == (LONG)PR_MW_PENDING)
{
PRFileDesc *bottom = PR_GetIdentitiesLayer(desc->fd, PR_NSPR_IO_LAYER);
PR_ASSERT(NULL != bottom);
@@ -1097,7 +1140,9 @@ PR_IMPLEMENT(PRStatus) PR_CancelWaitFileDesc(PRWaitGroup *group, PRRecvWait *des
do
{
PRRecvWait *done = (PRRecvWait*)head;
- if (done == desc) goto unlock;
+ if (done == desc) {
+ goto unlock;
+ }
head = PR_NEXT_LINK(head);
} while (head != &group->io_ready);
}
@@ -1120,7 +1165,9 @@ PR_IMPLEMENT(PRRecvWait*) PR_CancelWaitGroup(PRWaitGroup *group)
PRThread *me = _PR_MD_CURRENT_THREAD();
#endif
- if (NULL == group) group = mw_state->group;
+ if (NULL == group) {
+ group = mw_state->group;
+ }
PR_ASSERT(NULL != group);
if (NULL == group)
{
@@ -1131,17 +1178,20 @@ PR_IMPLEMENT(PRRecvWait*) PR_CancelWaitGroup(PRWaitGroup *group)
PR_Lock(group->ml);
if (_prmw_stopped != group->state)
{
- if (_prmw_running == group->state)
- group->state = _prmw_stopping; /* so nothing new comes in */
- if (0 == group->waiting_threads) /* is there anybody else? */
- group->state = _prmw_stopped; /* we can stop right now */
+ if (_prmw_running == group->state) {
+ group->state = _prmw_stopping; /* so nothing new comes in */
+ }
+ if (0 == group->waiting_threads) { /* is there anybody else? */
+ group->state = _prmw_stopped; /* we can stop right now */
+ }
else
{
PR_NotifyAllCondVar(group->new_business);
PR_NotifyAllCondVar(group->io_complete);
}
- while (_prmw_stopped != group->state)
+ while (_prmw_stopped != group->state) {
(void)PR_WaitCondVar(group->mw_manage, PR_INTERVAL_NO_TIMEOUT);
+ }
}
#ifdef WINNT
@@ -1155,11 +1205,11 @@ PR_IMPLEMENT(PRRecvWait*) PR_CancelWaitGroup(PRWaitGroup *group)
if (NULL != *desc)
{
if (InterlockedCompareExchange((LONG *)&(*desc)->outcome,
- (LONG)PR_MW_INTERRUPT, (LONG)PR_MW_PENDING)
+ (LONG)PR_MW_INTERRUPT, (LONG)PR_MW_PENDING)
== (LONG)PR_MW_PENDING)
{
PRFileDesc *bottom = PR_GetIdentitiesLayer(
- (*desc)->fd, PR_NSPR_IO_LAYER);
+ (*desc)->fd, PR_NSPR_IO_LAYER);
PR_ASSERT(NULL != bottom);
if (NULL == bottom)
{
@@ -1173,7 +1223,7 @@ PR_IMPLEMENT(PRRecvWait*) PR_CancelWaitGroup(PRWaitGroup *group)
if (closesocket(bottom->secret->md.osfd) == SOCKET_ERROR)
{
fprintf(stderr, "closesocket failed: %d\n",
- WSAGetLastError());
+ WSAGetLastError());
exit(1);
}
}
@@ -1202,32 +1252,34 @@ PR_IMPLEMENT(PRRecvWait*) PR_CancelWaitGroup(PRWaitGroup *group)
for (desc = &group->waiter->recv_wait; group->waiter->count > 0; ++desc)
{
PR_ASSERT(desc < &group->waiter->recv_wait + group->waiter->length);
- if (NULL != *desc)
+ if (NULL != *desc) {
_MW_DoneInternal(group, desc, PR_MW_INTERRUPT);
+ }
}
#endif
/* take first element of finished list and return it or NULL */
- if (PR_CLIST_IS_EMPTY(&group->io_ready))
+ if (PR_CLIST_IS_EMPTY(&group->io_ready)) {
PR_SetError(PR_GROUP_EMPTY_ERROR, 0);
+ }
else
{
PRCList *head = PR_LIST_HEAD(&group->io_ready);
PR_REMOVE_AND_INIT_LINK(head);
#ifdef WINNT
overlapped = (_MDOverlapped *)
- ((char *)head - offsetof(_MDOverlapped, data));
+ ((char *)head - offsetof(_MDOverlapped, data));
head = &overlapped->data.mw.desc->internal;
if (NULL != overlapped->data.mw.timer)
{
PR_ASSERT(PR_INTERVAL_NO_TIMEOUT
- != overlapped->data.mw.desc->timeout);
+ != overlapped->data.mw.desc->timeout);
CancelTimer(overlapped->data.mw.timer);
}
else
{
PR_ASSERT(PR_INTERVAL_NO_TIMEOUT
- == overlapped->data.mw.desc->timeout);
+ == overlapped->data.mw.desc->timeout);
}
PR_DELETE(overlapped);
#endif
@@ -1253,23 +1305,33 @@ PR_IMPLEMENT(PRWaitGroup*) PR_CreateWaitGroup(PRInt32 size /* ignored */)
}
/* the wait group itself */
wg->ml = PR_NewLock();
- if (NULL == wg->ml) goto failed_lock;
+ if (NULL == wg->ml) {
+ goto failed_lock;
+ }
wg->io_taken = PR_NewCondVar(wg->ml);
- if (NULL == wg->io_taken) goto failed_cvar0;
+ if (NULL == wg->io_taken) {
+ goto failed_cvar0;
+ }
wg->io_complete = PR_NewCondVar(wg->ml);
- if (NULL == wg->io_complete) goto failed_cvar1;
+ if (NULL == wg->io_complete) {
+ goto failed_cvar1;
+ }
wg->new_business = PR_NewCondVar(wg->ml);
- if (NULL == wg->new_business) goto failed_cvar2;
+ if (NULL == wg->new_business) {
+ goto failed_cvar2;
+ }
wg->mw_manage = PR_NewCondVar(wg->ml);
- if (NULL == wg->mw_manage) goto failed_cvar3;
+ if (NULL == wg->mw_manage) {
+ goto failed_cvar3;
+ }
PR_INIT_CLIST(&wg->group_link);
PR_INIT_CLIST(&wg->io_ready);
/* the waiters sequence */
wg->waiter = (_PRWaiterHash*)PR_CALLOC(
- sizeof(_PRWaiterHash) +
- (_PR_DEFAULT_HASH_LENGTH * sizeof(PRRecvWait*)));
+ sizeof(_PRWaiterHash) +
+ (_PR_DEFAULT_HASH_LENGTH * sizeof(PRRecvWait*)));
if (NULL == wg->waiter)
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
@@ -1309,14 +1371,16 @@ failed:
PR_IMPLEMENT(PRStatus) PR_DestroyWaitGroup(PRWaitGroup *group)
{
PRStatus rv = PR_SUCCESS;
- if (NULL == group) group = mw_state->group;
+ if (NULL == group) {
+ group = mw_state->group;
+ }
PR_ASSERT(NULL != group);
if (NULL != group)
{
PR_Lock(group->ml);
if ((group->waiting_threads == 0)
- && (group->waiter->count == 0)
- && PR_CLIST_IS_EMPTY(&group->io_ready))
+ && (group->waiter->count == 0)
+ && PR_CLIST_IS_EMPTY(&group->io_ready))
{
group->state = _prmw_stopped;
}
@@ -1326,7 +1390,9 @@ PR_IMPLEMENT(PRStatus) PR_DestroyWaitGroup(PRWaitGroup *group)
rv = PR_FAILURE;
}
PR_Unlock(group->ml);
- if (PR_FAILURE == rv) return rv;
+ if (PR_FAILURE == rv) {
+ return rv;
+ }
PR_Lock(mw_lock);
PR_REMOVE_LINK(&group->group_link);
@@ -1347,7 +1413,9 @@ PR_IMPLEMENT(PRStatus) PR_DestroyWaitGroup(PRWaitGroup *group)
PR_DestroyCondVar(group->io_complete);
PR_DestroyCondVar(group->io_taken);
PR_DestroyLock(group->ml);
- if (group == mw_state->group) mw_state->group = NULL;
+ if (group == mw_state->group) {
+ mw_state->group = NULL;
+ }
PR_DELETE(group);
}
else
@@ -1368,7 +1436,9 @@ PR_IMPLEMENT(PRStatus) PR_DestroyWaitGroup(PRWaitGroup *group)
PR_IMPLEMENT(PRMWaitEnumerator*) PR_CreateMWaitEnumerator(PRWaitGroup *group)
{
PRMWaitEnumerator *enumerator = PR_NEWZAP(PRMWaitEnumerator);
- if (NULL == enumerator) PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ if (NULL == enumerator) {
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ }
else
{
enumerator->group = group;
@@ -1395,12 +1465,14 @@ PR_IMPLEMENT(PRRecvWait*) PR_EnumerateWaitGroup(
PRMWaitEnumerator *enumerator, const PRRecvWait *previous)
{
PRRecvWait *result = NULL;
-
+
/* entry point sanity checking */
PR_ASSERT(NULL != enumerator);
PR_ASSERT(_PR_ENUM_SEALED == enumerator->seal);
if ((NULL == enumerator)
- || (_PR_ENUM_SEALED != enumerator->seal)) goto bad_argument;
+ || (_PR_ENUM_SEALED != enumerator->seal)) {
+ goto bad_argument;
+ }
/* beginning of enumeration */
if (NULL == previous)
@@ -1424,11 +1496,14 @@ PR_IMPLEMENT(PRRecvWait*) PR_EnumerateWaitGroup(
{
PRThread *me = PR_GetCurrentThread();
PR_ASSERT(me == enumerator->thread);
- if (me != enumerator->thread) goto bad_argument;
+ if (me != enumerator->thread) {
+ goto bad_argument;
+ }
/* need to restart the enumeration */
- if (enumerator->p_timestamp != enumerator->group->p_timestamp)
+ if (enumerator->p_timestamp != enumerator->group->p_timestamp) {
return PR_EnumerateWaitGroup(enumerator, NULL);
+ }
}
/* actually progress the enumeration */
@@ -1439,7 +1514,9 @@ PR_IMPLEMENT(PRRecvWait*) PR_EnumerateWaitGroup(
#endif
while (enumerator->index++ < enumerator->group->waiter->length)
{
- if (NULL != (result = *(enumerator->waiter)++)) break;
+ if (NULL != (result = *(enumerator->waiter)++)) {
+ break;
+ }
}
#if defined(WINNT)
_PR_MD_UNLOCK(&enumerator->group->mdlock);