Commit a53079e3 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Change the OS/X workaround for pthread_cond_timedwait() returning EINVAL

parent 5424da94
...@@ -229,47 +229,47 @@ Lck_CondWaitUntil(pthread_cond_t *cond, struct lock *lck, vtim_real when) ...@@ -229,47 +229,47 @@ Lck_CondWaitUntil(pthread_cond_t *cond, struct lock *lck, vtim_real when)
struct ilck *ilck; struct ilck *ilck;
struct timespec ts; struct timespec ts;
AN(lck);
CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
AN(ilck->held);
assert(pthread_equal(ilck->owner, pthread_self()));
ilck->held = 0;
if (when == 0) {
errno = pthread_cond_wait(cond, &ilck->mtx);
AZ(errno);
} else {
assert(when > 1e9);
ts = VTIM_timespec(when);
assert(ts.tv_nsec >= 0 && ts.tv_nsec <= 999999999);
errno = pthread_cond_timedwait(cond, &ilck->mtx, &ts);
#if defined (__APPLE__) #if defined (__APPLE__)
/* /*
* I hate woo-doo programming in all it's forms and all it's * I hate woo-doo programming in all it's forms and all it's
* manifestations, but for reasons I utterly fail to isolate * manifestations, but for reasons I utterly fail to isolate,
* yielding here is stops OSX from throwing a EINVAL to the * OSX sometimes throws an EINVAL.
* pthread_cond_wait(3) call.
* *
* I have tried very hard to determine if any of the three * I have tried very hard to determine if any of the three
* arguments are in fact invalid, and found nothing which * arguments are in fact invalid, and found nothing which
* even hints that it might be the case, and with high probability * even hints that it might be the case.
* repeating the failed call with the exact same arguments
* will succeed.
* *
* If you want to dive into this you can trigger the situation * So far I have yet to see a failure if the exact same
* approx 30% of the time with: * call is repeated after a very short sleep.
* *
* cd .../vmods && make -j check * Calling pthread_yield_np() instead of sleaping /mostly/
* works as well, but still fails sometimes.
* *
* Env: * Env:
* Darwin Kernel Version 20.5.0: * Darwin Kernel Version 20.5.0:
* Sat May 8 05:10:31 PDT 2021; * Sat May 8 05:10:31 PDT 2021;
* root:xnu-7195.121.3~9/RELEASE_ARM64_T8101 arm64 * root:xnu-7195.121.3~9/RELEASE_ARM64_T8101 arm64
* *
* 20211027 /phk * 20220329 /phk
*/ */
pthread_yield_np(); if (errno == EINVAL) {
#endif usleep(100);
AN(lck);
CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
AN(ilck->held);
assert(pthread_equal(ilck->owner, pthread_self()));
ilck->held = 0;
if (when == 0) {
errno = pthread_cond_wait(cond, &ilck->mtx);
AZ(errno);
} else {
assert(when > 1e9);
ts = VTIM_timespec(when);
assert(ts.tv_nsec >= 0 && ts.tv_nsec <= 999999999);
errno = pthread_cond_timedwait(cond, &ilck->mtx, &ts); errno = pthread_cond_timedwait(cond, &ilck->mtx, &ts);
}
#endif
assert(errno == 0 || assert(errno == 0 ||
errno == ETIMEDOUT || errno == ETIMEDOUT ||
errno == EINTR); errno == EINTR);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment