From 60dd395a5b083b384d2fc39e195f411b75e97fc9 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 6 Feb 2013 16:04:46 +0100 Subject: [PATCH] Revert "darwin: merge uv_cond_timedwait implementation" Using mach_absolute_time() for the pthread_cond_timedwait() timeout breaks a number of tests on OS X 10.8.2. This reverts commit 8311390f13177f3086ecdac875115d2d4cc2688b. --- src/unix/thread.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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__)