Skip to content

Commit a14f1e1

Browse files
committed
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.
1 parent 12a60ac commit a14f1e1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/shims/lock.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,13 @@ _dispatch_wait_on_address(uint32_t volatile *_address, uint32_t value,
508508
}
509509
return _dispatch_futex_wait(address, value, NULL, FUTEX_PRIVATE_FLAG);
510510
#elif defined(_WIN32)
511-
return WaitOnAddress(address, &value, sizeof(value), INFINITE) == TRUE;
511+
// Round up to the nearest ms as `WaitOnAddress` takes a timeout in ms.
512+
// Integral division will truncate, so make sure that we do the roundup.
513+
DWORD dwMilliseconds =
514+
nsecs == DISPATCH_TIME_FOREVER
515+
? INFINITE : ((nsecs + 1000000) / 1000000);
516+
if (dwMilliseconds == 0) return ETIMEDOUT;
517+
return WaitOnAddress(address, &value, sizeof(value), dwMilliseconds) == TRUE;
512518
#else
513519
#error _dispatch_wait_on_address unimplemented for this platform
514520
#endif

0 commit comments

Comments
 (0)