From 2a997942dbcc34ff1c9078edd2faff458da84081 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 23 Feb 2023 11:09:23 -0800 Subject: [PATCH] QWaitCondition/Android: remove support for relative time waits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This actually saves two clock_gettime(CLOCK_MONOTONIC) system calls (albeit to the vDSO): one inside QDeadlineTimer::remainingTimeNSecs() to calculate the remaining time from the deadline, then one other inside pthread_cond_timedwait_relative_np() to calculate the deadline from the timeout, so it can place the FUTEX_WAIT_BITSET system call. In fact, I can't find __pthread_cond_timedwait_relative() in the Bionic source any more. The last reference was removed in 2015, when Bionic started using FUTEX_WAIT_BITSET. So this commit is just removing dead code in current Android. Pick-to: 6.5 Change-Id: Ieec322d73c1e40ad95c8fffd174689c4fcff40ae Reviewed-by: MÃ¥rten Nordheim --- src/corelib/thread/qwaitcondition_unix.cpp | 24 ---------------------- 1 file changed, 24 deletions(-) diff --git a/src/corelib/thread/qwaitcondition_unix.cpp b/src/corelib/thread/qwaitcondition_unix.cpp index 68fb92a0c8..ec215cfb23 100644 --- a/src/corelib/thread/qwaitcondition_unix.cpp +++ b/src/corelib/thread/qwaitcondition_unix.cpp @@ -22,17 +22,6 @@ QT_BEGIN_NAMESPACE -#ifdef Q_OS_ANDROID -// pthread_condattr_setclock is available only since Android 5.0. On older versions, there's -// a private function for relative waits (hidden in 5.0). -// Use weakref so we can determine at runtime whether each of them is present. -static int local_condattr_setclock(pthread_condattr_t*, clockid_t) -__attribute__((weakref("pthread_condattr_setclock"))); - -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) @@ -49,12 +38,7 @@ void qt_initialize_pthread_cond(pthread_cond_t *cond, const char *where) pthread_condattr_init(&condattr); auto destroy = qScopeGuard([&] { pthread_condattr_destroy(&condattr); }); -#if defined(Q_OS_ANDROID) - if (local_condattr_setclock) - local_condattr_setclock(&condattr, CLOCK_MONOTONIC); -#else pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC); -#endif #endif report_error(pthread_cond_init(cond, attrp), where, "cv init"); @@ -91,14 +75,6 @@ public: int wait_relative(QDeadlineTimer deadline) { timespec ti; -#ifdef Q_OS_ANDROID - if (!local_condattr_setclock && local_cond_timedwait_relative) { - qint64 nsec = deadline.remainingTimeNSecs(); - ti.tv_sec = nsec / (1000 * 1000 * 1000); - ti.tv_nsec = nsec - ti.tv_sec * 1000 * 1000 * 1000; - return local_cond_timedwait_relative(&cond, &mutex, &ti); - } -#endif qt_abstime_for_timeout(&ti, deadline); return pthread_cond_timedwait(&cond, &mutex, &ti); }