From ef9d674a4812cf1e39b140a9937c0d07886c4275 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Fri, 11 Jun 2021 02:07:36 +0200 Subject: thread(win32): Make sure cond_wait and cond_wait_timeout return a value --- src/thread.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/thread.c b/src/thread.c index dbe93c8..7dc968c 100644 --- a/src/thread.c +++ b/src/thread.c @@ -177,7 +177,13 @@ int cond_wait(cond_t* cond, mutex_t* mutex) { #ifdef WIN32 mutex_unlock(mutex); - WaitForSingleObject(cond->sem, INFINITE); + DWORD res = WaitForSingleObject(cond->sem, INFINITE); + switch (res) { + case WAIT_OBJECT_0: + return 0; + default: + return -1; + } #else return pthread_cond_wait(cond, mutex); #endif @@ -187,7 +193,14 @@ int cond_wait_timeout(cond_t* cond, mutex_t* mutex, unsigned int timeout_ms) { #ifdef WIN32 mutex_unlock(mutex); - WaitForSingleObject(cond->sem, timeout_ms); + DWORD res = WaitForSingleObject(cond->sem, timeout_ms); + switch (res) { + case WAIT_OBJECT_0: + case WAIT_TIMEOUT: + return 0; + default: + return -1; + } #else struct timespec ts; struct timeval now; -- cgit v1.1-32-gdbae