From a14f1e15c019098ce81d37fdf03123bf7bf90ed9 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 21 May 2022 08:28:48 -0700 Subject: [PATCH] shims: adjust `WaitOnAddress` usage on Windows We would previously unconditionally wait indefinitely on the address rather than waiting for the specified duration. Adjust the timeout parameter to the `WaitOnAddress` to ensure that we get the correct behaviour. --- src/shims/lock.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/shims/lock.c b/src/shims/lock.c index d4d63134a..62fa6f385 100644 --- a/src/shims/lock.c +++ b/src/shims/lock.c @@ -508,7 +508,13 @@ _dispatch_wait_on_address(uint32_t volatile *_address, uint32_t value, } return _dispatch_futex_wait(address, value, NULL, FUTEX_PRIVATE_FLAG); #elif defined(_WIN32) - return WaitOnAddress(address, &value, sizeof(value), INFINITE) == TRUE; + // Round up to the nearest ms as `WaitOnAddress` takes a timeout in ms. + // Integral division will truncate, so make sure that we do the roundup. + DWORD dwMilliseconds = + nsecs == DISPATCH_TIME_FOREVER + ? INFINITE : ((nsecs + 1000000) / 1000000); + if (dwMilliseconds == 0) return ETIMEDOUT; + return WaitOnAddress(address, &value, sizeof(value), dwMilliseconds) == TRUE; #else #error _dispatch_wait_on_address unimplemented for this platform #endif