From dcf9c403ba8e903bb52a6fb656c7e2de23383c10 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 30 Mar 2013 10:52:52 -0700 Subject: Use Bionic's __pthread_cond_timedwait_relative The Linux futex interface uses relative timeouts anyway, so this avoids a double round-trip through clock_gettime: once in Qt code to calculate absolute from relative and once in libc for reversing. Glibc does not offer such a function because its pthread_cond objects use a kernel interface that works on absolute times. Change-Id: I8fbcd3f73d4364a16716b0eea17e8f5f9ab5cd05 Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Thiago Macieira --- src/corelib/thread/qwaitcondition_unix.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/corelib/thread/qwaitcondition_unix.cpp b/src/corelib/thread/qwaitcondition_unix.cpp index 59c4035232..616a4bdfb8 100644 --- a/src/corelib/thread/qwaitcondition_unix.cpp +++ b/src/corelib/thread/qwaitcondition_unix.cpp @@ -59,6 +59,14 @@ QT_BEGIN_NAMESPACE +#ifdef Q_OS_ANDROID +// Android lacks pthread_condattr_setclock, but it does have a nice function +// for relative waits. Use weakref so we can determine at runtime whether it is +// present. +static int local_cond_timedwait_relative(pthread_cond_t*, pthread_mutex_t *, const timespec *) +__attribute__((weakref("__pthread_cond_timedwait_relative"))); +#endif + static void report_error(int code, const char *where, const char *what) { if (code != 0) @@ -107,6 +115,13 @@ public: int wait_relative(unsigned long time) { timespec ti; +#ifdef Q_OS_ANDROID + if (Q_LIKELY(local_cond_timedwait_relative)) { + ti.tv_sec = time / 1000; + ti.tv_nsec = time % 1000 * Q_UINT64_C(1000) * 1000; + return local_cond_timedwait_relative(&cond, &mutex, &ti); + } +#endif qt_abstime_for_timeout(&ti, time); return pthread_cond_timedwait(&cond, &mutex, &ti); } -- cgit v1.2.3