Skip to content

Commit

Permalink
Fix a bug in our win32 condition implementation
Browse files Browse the repository at this point in the history
The do ... while loop in our wait code could spin while waiting
because the event object wasn't reset until there were no longer any
events waiting to be woken up.  We also want to reset the event object
if the count of events to wake up reaches zero.

Found by Chris Davis.  Fixes bug 3053358.
  • Loading branch information
nmathewson committed Aug 30, 2010
1 parent d61b2f3 commit acc4aca
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions evthread_win32.c
Expand Up @@ -253,20 +253,30 @@ evthread_win32_cond_wait(void *_cond, void *_lock, const struct timeval *tv)
--cond->n_waiting; --cond->n_waiting;
result = 0; result = 0;
waiting = 0; waiting = 0;
goto out;
} else if (res != WAIT_OBJECT_0) { } else if (res != WAIT_OBJECT_0) {
result = (res==WAIT_TIMEOUT) ? 1 : -1; result = (res==WAIT_TIMEOUT) ? 1 : -1;
--cond->n_waiting; --cond->n_waiting;
waiting = 0; waiting = 0;
goto out;
} else if (ms != INFINITE) { } else if (ms != INFINITE) {
endTime = GetTickCount(); endTime = GetTickCount();
if (startTime + ms_orig <= endTime) { if (startTime + ms_orig <= endTime) {
result = 1; /* Timeout */ result = 1; /* Timeout */
--cond->n_waiting; --cond->n_waiting;
waiting = 0; waiting = 0;
goto out;
} else { } else {
ms = startTime + ms_orig - endTime; ms = startTime + ms_orig - endTime;
} }
} }
/* If we make it here, we are still waiting. */
if (cond->n_to_wake == 0) {
/* There is nobody else who should wake up; reset
* the event. */
ResetEvent(cond->event);
}
out:
LeaveCriticalSection(&cond->lock); LeaveCriticalSection(&cond->lock);
} while (waiting); } while (waiting);


Expand Down

0 comments on commit acc4aca

Please sign in to comment.