Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix a bug in our win32 condition implementation

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...
commit acc4aca49e246a46e03f8978517c9b3d23b1baea 1 parent d61b2f3
Nick Mathewson authored
Showing with 10 additions and 0 deletions.
  1. +10 −0 evthread_win32.c
View
10 evthread_win32.c
@@ -253,20 +253,30 @@ evthread_win32_cond_wait(void *_cond, void *_lock, const struct timeval *tv)
--cond->n_waiting;
result = 0;
waiting = 0;
+ goto out;
} else if (res != WAIT_OBJECT_0) {
result = (res==WAIT_TIMEOUT) ? 1 : -1;
--cond->n_waiting;
waiting = 0;
+ goto out;
} else if (ms != INFINITE) {
endTime = GetTickCount();
if (startTime + ms_orig <= endTime) {
result = 1; /* Timeout */
--cond->n_waiting;
waiting = 0;
+ goto out;
} else {
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);
} while (waiting);
Please sign in to comment.
Something went wrong with that request. Please try again.