Skip to content

Commit

Permalink
OSX returns EINVAL for pthread_cond_timedwait(2) timestamps in the past.
Browse files Browse the repository at this point in the history
Fixes	#1853
  • Loading branch information
bsdphk committed Jan 20, 2020
1 parent d241d80 commit e5e545f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bin/varnishd/cache/cache_lck.c
Expand Up @@ -40,6 +40,10 @@
#include <stdlib.h>
#include <stdio.h>

#if defined (__APPLE__)
# include "vtim.h"
#endif

#include "VSC_lck.h"

struct ilck {
Expand Down Expand Up @@ -214,6 +218,19 @@ Lck_CondWait(pthread_cond_t *cond, struct lock *lck, vtim_real when)
ts.tv_sec = (long)t;
assert(ts.tv_nsec >= 0 && ts.tv_nsec < 999999999);
errno = pthread_cond_timedwait(cond, &ilck->mtx, &ts);
#if defined (__APPLE__)
if (errno == EINVAL && when > VTIM_real()) {
/*
* Most kernels treat this as honest error,
* recognizing that a thread has no way to
* prevent being descheduled between a user-
* land check of the timestamp, and getting
* the timestamp into the kernel before it
* expires. OS/X on the other hand...
*/
errno = ETIMEDOUT;
}
#endif
assert(errno == 0 ||
errno == ETIMEDOUT ||
errno == EINTR);
Expand Down

0 comments on commit e5e545f

Please sign in to comment.