QWaitCondition/Unix: Modernize the call to pthread_condattr_setclock

This avoids creating and destroying the pthread_condattr_t on systems
without a monotonic clock (INTEGRITY) or for which we can't ask that
pthread_cond_t use it (Darwin).

Change-Id: Ieec322d73c1e40ad95c8fffd1746878316ab8708
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
bb10
Thiago Macieira 2023-02-23 10:28:28 -08:00
parent 840af18b8d
commit ccd3f2369a
1 changed files with 8 additions and 5 deletions

View File

@ -41,20 +41,23 @@ static void report_error(int code, const char *where, const char *what)
void qt_initialize_pthread_cond(pthread_cond_t *cond, const char *where)
{
pthread_condattr_t *attrp = nullptr;
#if defined(CLOCK_MONOTONIC) && !defined(Q_OS_DARWIN)
pthread_condattr_t condattr;
attrp = &condattr;
pthread_condattr_init(&condattr);
#ifdef CLOCK_MONOTONIC
auto destroy = qScopeGuard([&] { pthread_condattr_destroy(&condattr); });
#if defined(Q_OS_ANDROID)
if (local_condattr_setclock)
local_condattr_setclock(&condattr, CLOCK_MONOTONIC);
#elif !defined(Q_OS_DARWIN)
// Darwin doesn't have this function
#else
pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC);
#endif
#endif
report_error(pthread_cond_init(cond, &condattr), where, "cv init");
pthread_condattr_destroy(&condattr);
report_error(pthread_cond_init(cond, attrp), where, "cv init");
}
void qt_abstime_for_timeout(timespec *ts, QDeadlineTimer deadline)