diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2023-02-23 10:28:28 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2023-04-18 19:23:40 -0300 |
commit | ccd3f2369a514a40c4d0427415bd7fcad9382002 (patch) | |
tree | 77a585749f31c2835726e9dd1030083ae78ff6cc /src | |
parent | 840af18b8da2d903ea773cd135800734f93724a8 (diff) |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/thread/qwaitcondition_unix.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/corelib/thread/qwaitcondition_unix.cpp b/src/corelib/thread/qwaitcondition_unix.cpp index 443753bea5..68fb92a0c8 100644 --- a/src/corelib/thread/qwaitcondition_unix.cpp +++ b/src/corelib/thread/qwaitcondition_unix.cpp @@ -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) |