darwin: workaround apple pthread_cond_wait bug (#4166)

Under heavy workloads pthread_cond_wait on macOS can return EINVAL while
all the input parameters are correct.

As it happens due to a syscall having an errno of EBUSY we can detect it
and work around it.

Fixes: https://github.com/libuv/libuv/issues/4165
This commit is contained in:
Julien Roncaglia 2023-10-13 21:32:46 +02:00 committed by GitHub
parent d8669609d8
commit 197f453b76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -789,11 +789,33 @@ void uv_cond_broadcast(uv_cond_t* cond) {
abort();
}
#if defined(__APPLE__) && defined(__MACH__)
void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex) {
int r;
errno = 0;
r = pthread_cond_wait(cond, mutex);
/* Workaround for a bug in OS X at least up to 13.6
* See https://github.com/libuv/libuv/issues/4165
*/
if (r == EINVAL)
if (errno == EBUSY)
return;
if (r)
abort();
}
#else /* !(defined(__APPLE__) && defined(__MACH__)) */
void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex) {
if (pthread_cond_wait(cond, mutex))
abort();
}
#endif
int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) {
int r;