c11/threads: Re-align return values for timed waits
authorJason Ekstrand <jason@jlekstrand.net>
Wed, 27 Oct 2021 21:32:24 +0000 (16:32 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Tue, 16 Nov 2021 16:02:08 +0000 (10:02 -0600)
They're supposed to return thrd_timedout (which we mistakenly named
thrd_timeout), not thrd_busy.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13427>

include/c11/threads.h
include/c11/threads_posix.h
include/c11/threads_win32.h
src/egl/drivers/dri2/egl_dri2.c
src/util/cnd_monotonic.h

index 3c3f23a..790f52c 100644 (file)
@@ -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
index 45cb607..802526a 100644 (file)
@@ -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();
     }
index 02c2a73..8c014fa 100644 (file)
@@ -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();
     }
index d687533..b1e4a9d 100644 (file)
@@ -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 {
index 983dfb8..35a3d2b 100644 (file)
@@ -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
 }