Commit 220126f8 authored by Kenton Varda's avatar Kenton Varda

Adjust Windows sleep time to avoid premature wakeup.

parent f38467a0
......@@ -511,6 +511,11 @@ void Mutex::lockWhen(Predicate& predicate, Maybe<Duration> timeout) {
LARGE_INTEGER endTime;
KJ_IF_MAYBE(t, timeout) {
// Windows sleeps are inaccurate -- they can be longer *or shorter* than the requested amount.
// For many use cases of our API, a too-short sleep would be unacceptable. Experimentally, it
// seems like sleeps can be up to half a millisecond short, so we'll add a millisecond.
*t += 500 * kj::MICROSECONDS;
// Compute initial sleep time.
sleepMs = *t / kj::MILLISECONDS;
if (*t % kj::MILLISECONDS > 0 * kj::SECONDS) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment