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: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13427>
This commit is contained in:
Jason Ekstrand 2021-10-27 16:32:24 -05:00
parent 13ab3757bb
commit f3843b11c9
5 changed files with 9 additions and 9 deletions

View 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

View 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();
}

View 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();
}

View 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 {

View 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
}