From 36ea2cb2954934d91f0636504cf0c7df2593903c Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Mon, 28 Aug 2017 17:18:57 +0200 Subject: [PATCH] android: fix uv_cond_timedwait on API level < 21 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit partly reverses libuv#1441. It is true that pthread_cond_timedwait is available on older API levels, but if we do not call pthread_condattr_setclock then we cannot use timestamps from CLOCK_MONOTONIC with pthread_cond_timedwait. PR-URL: https://github.com/libuv/libuv/pull/1511 Reviewed-By: Saúl Ibarra Corretgé --- src/unix/thread.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/unix/thread.c b/src/unix/thread.c index c7ff3fa4..f8846225 100644 --- a/src/unix/thread.c +++ b/src/unix/thread.c @@ -618,7 +618,16 @@ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) { timeout += uv__hrtime(UV_CLOCK_PRECISE); ts.tv_sec = timeout / NANOSEC; ts.tv_nsec = timeout % NANOSEC; +#if defined(__ANDROID_API__) && __ANDROID_API__ < 21 + + /* + * The bionic pthread implementation doesn't support CLOCK_MONOTONIC, + * but has this alternative function instead. + */ + r = pthread_cond_timedwait_monotonic_np(cond, mutex, &ts); +#else r = pthread_cond_timedwait(cond, mutex, &ts); +#endif /* __ANDROID_API__ */ #endif