From f3843b11c9127a16b7381c9d6d0091ca59a1d029 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 27 Oct 2021 16:32:24 -0500 Subject: [PATCH] c11/threads: Re-align return values for timed waits They're supposed to return thrd_timedout (which we mistakenly named thrd_timeout), not thrd_busy. Part-of: --- include/c11/threads.h | 2 +- include/c11/threads_posix.h | 6 +++--- include/c11/threads_win32.h | 4 ++-- src/egl/drivers/dri2/egl_dri2.c | 2 +- src/util/cnd_monotonic.h | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/c11/threads.h b/include/c11/threads.h index 3c3f23a8ab8..790f52cb49f 100644 --- a/include/c11/threads.h +++ b/include/c11/threads.h @@ -52,7 +52,7 @@ enum { enum { thrd_success = 0, // succeeded - thrd_timeout, // timeout + thrd_timedout, // timed out thrd_error, // failed thrd_busy, // resource busy thrd_nomem // out of memory diff --git a/include/c11/threads_posix.h b/include/c11/threads_posix.h index 45cb6075e6e..802526a77c8 100644 --- a/include/c11/threads_posix.h +++ b/include/c11/threads_posix.h @@ -142,7 +142,7 @@ cnd_timedwait(cnd_t *cond, mtx_t *mtx, const struct timespec *abs_time) rt = pthread_cond_timedwait(cond, mtx, abs_time); if (rt == ETIMEDOUT) - return thrd_busy; + return thrd_timedout; return (rt == 0) ? thrd_success : thrd_error; } @@ -242,14 +242,14 @@ mtx_timedlock(mtx_t *mtx, const struct timespec *ts) rt = pthread_mutex_timedlock(mtx, ts); if (rt == 0) return thrd_success; - return (rt == ETIMEDOUT) ? thrd_busy : thrd_error; + return (rt == ETIMEDOUT) ? thrd_timedout : thrd_error; #else time_t expire = time(NULL); expire += ts->tv_sec; while (mtx_trylock(mtx) != thrd_success) { time_t now = time(NULL); if (expire < now) - return thrd_busy; + return thrd_timedout; // busy loop! thrd_yield(); } diff --git a/include/c11/threads_win32.h b/include/c11/threads_win32.h index 02c2a73dda1..8c014fab45c 100644 --- a/include/c11/threads_win32.h +++ b/include/c11/threads_win32.h @@ -259,7 +259,7 @@ cnd_timedwait(cnd_t *cond, mtx_t *mtx, const struct timespec *abs_time) const DWORD timeout = impl_abs2relmsec(abs_time); if (SleepConditionVariableCS(cond, mtx, timeout)) return thrd_success; - return (GetLastError() == ERROR_TIMEOUT) ? thrd_busy : thrd_error; + return (GetLastError() == ERROR_TIMEOUT) ? thrd_timedout : thrd_error; #else return thrd_error; #endif @@ -317,7 +317,7 @@ mtx_timedlock(mtx_t *mtx, const struct timespec *ts) #ifdef HAVE_TIMESPEC_GET while (mtx_trylock(mtx) != thrd_success) { if (impl_abs2relmsec(ts) == 0) - return thrd_busy; + return thrd_timedout; // busy loop! thrd_yield(); } diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index d687533168b..b1e4a9dfe13 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -3598,7 +3598,7 @@ dri2_client_wait_sync(_EGLDisplay *disp, _EGLSync *sync, ret = cnd_timedwait(&dri2_sync->cond, &dri2_sync->mutex, &expire); mtx_unlock(&dri2_sync->mutex); - if (ret == thrd_busy) { + if (ret == thrd_timedout) { if (dri2_sync->base.SyncStatus == EGL_UNSIGNALED_KHR) { ret = EGL_TIMEOUT_EXPIRED_KHR; } else { diff --git a/src/util/cnd_monotonic.h b/src/util/cnd_monotonic.h index 983dfb8e55c..35a3d2b76de 100644 --- a/src/util/cnd_monotonic.h +++ b/src/util/cnd_monotonic.h @@ -119,11 +119,11 @@ u_cnd_monotonic_timedwait(struct u_cnd_monotonic *cond, mtx_t *mtx, const struct const DWORD timeout = (future > now) ? (DWORD)(future - now) : 0; if (SleepConditionVariableCS(&cond->condvar, mtx, timeout)) return thrd_success; - return (GetLastError() == ERROR_TIMEOUT) ? thrd_busy : thrd_error; + return (GetLastError() == ERROR_TIMEOUT) ? thrd_timedout : thrd_error; #else int rt = pthread_cond_timedwait(&cond->cond, mtx, abs_time); if (rt == ETIMEDOUT) - return thrd_busy; + return thrd_timedout; return (rt == 0) ? thrd_success : thrd_error; #endif }