Fix busy loop in windows (#131)

* Fix busy loop in windows

* Nick wants the while loop gone

* Fix continue leftover

Co-authored-by: Nikolay Bogoychev <nheart@gmail.com>
This commit is contained in:
Kenneth Heafield 2021-05-06 00:21:50 +01:00 committed by GitHub
parent a63533b241
commit c61b2bdd10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,17 +113,15 @@ class Semaphore {
void wait() {
while (true) {
switch (WaitForSingleObject(sem_, 0L)) {
case WAIT_OBJECT_0:
return;
case WAIT_ABANDONED:
ABORT("A semaphore can't be abandoned, confused by Windows");
case WAIT_TIMEOUT:
continue;
case WAIT_FAILED:
ABORT("Waiting on Semaphore failed {}", GetLastError());
}
switch (WaitForSingleObject(sem_, INFINITE)) {
case WAIT_OBJECT_0:
return;
case WAIT_ABANDONED:
ABORT("A semaphore can't be abandoned, confused by Windows");
case WAIT_TIMEOUT:
ABORT("Timeout on an infinite wait?");
case WAIT_FAILED:
ABORT("Waiting on Semaphore failed {}", GetLastError());
}
}