diff --git a/src/unix/thread.c b/src/unix/thread.c index 8d15c9b6..4fd5d2f5 100644 --- a/src/unix/thread.c +++ b/src/unix/thread.c @@ -323,6 +323,31 @@ void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex) { abort(); } +#if defined(__APPLE__) && defined(__MACH__) + +int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) { + int r; + struct timeval tv; + struct timespec ts; + uint64_t abstime; + + gettimeofday(&tv, NULL); + abstime = tv.tv_sec * 1e9 + tv.tv_usec * 1e3 + timeout; + ts.tv_sec = abstime / NANOSEC; + ts.tv_nsec = abstime % NANOSEC; + r = pthread_cond_timedwait(cond, mutex, &ts); + + if (r == 0) + return 0; + + if (r == ETIMEDOUT) + return -1; + + abort(); + return -1; /* Satisfy the compiler. */ +} + +#else /* !(defined(__APPLE__) && defined(__MACH__)) */ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) { int r; @@ -344,6 +369,8 @@ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) { return -1; /* Satisfy the compiler. */ } +#endif /* defined(__APPLE__) && defined(__MACH__) */ + #if defined(__APPLE__) && defined(__MACH__)