From a945124a4212238f4d752ff2f2f3065c5adc1655 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 17 Dec 2014 18:47:52 -0800 Subject: Make the detection of the number of cores on Unix prettier This is a no-op change. It doesn't improve or worsen the code at all. Change-Id: Ifd5273842370ca9bce0ed74f2f2d54d453797948 Reviewed-by: Thiago Macieira --- src/corelib/thread/qthread_unix.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/corelib/thread') diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 9a14503584..e4338e10b4 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -395,14 +395,13 @@ Qt::HANDLE QThread::currentThreadId() Q_DECL_NOTHROW int QThread::idealThreadCount() Q_DECL_NOTHROW { - int cores = -1; + int cores = 1; #if defined(Q_OS_HPUX) // HP-UX struct pst_dynamic psd; if (pstat_getdynamic(&psd, sizeof(psd), 1, 0) == -1) { perror("pstat_getdynamic"); - cores = -1; } else { cores = (int)psd.psd_proc_cnt; } @@ -414,7 +413,6 @@ int QThread::idealThreadCount() Q_DECL_NOTHROW mib[1] = HW_NCPU; if (sysctl(mib, 2, &cores, &len, NULL, 0) != 0) { perror("sysctl"); - cores = -1; } #elif defined(Q_OS_IRIX) // IRIX @@ -449,9 +447,9 @@ int QThread::idealThreadCount() Q_DECL_NOTHROW #else // the rest: Linux, Solaris, AIX, Tru64 cores = (int)sysconf(_SC_NPROCESSORS_ONLN); -#endif if (cores == -1) return 1; +#endif return cores; } -- cgit v1.2.3 From 921dd85c7a90bf7432d50bd9f631d065f5281d34 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Tue, 10 Feb 2015 16:01:22 +0100 Subject: Android: fix timed QWaitCondition::wait() on Android >= 5.0. wait() was always returning immediately, regardless of the timeout value, due to a timespec comparison from different clock types. On Android 5.0, qt_gettime() uses the monotonic clock but the wait condition was using the real time clock. __pthread_cond_timedwait_relative() is not exported anymore in Android 5.0, we therefore fall back to pthread_cond_timedwait(). Since the monotonic clock is now available, qt_gettime returns a time based on it. The wait condition consequently needs to use the monotonic clock. Change-Id: Ie7cf909b81107edd7207c3c039b3ec1f5422303f Reviewed-by: Thiago Macieira Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/corelib/thread/qwaitcondition_unix.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/corelib/thread') diff --git a/src/corelib/thread/qwaitcondition_unix.cpp b/src/corelib/thread/qwaitcondition_unix.cpp index 3bcf3202a1..e03187196f 100644 --- a/src/corelib/thread/qwaitcondition_unix.cpp +++ b/src/corelib/thread/qwaitcondition_unix.cpp @@ -52,9 +52,12 @@ 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. +// 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 @@ -70,9 +73,14 @@ void qt_initialize_pthread_cond(pthread_cond_t *cond, const char *where) pthread_condattr_t condattr; pthread_condattr_init(&condattr); -#if !defined(Q_OS_MAC) && !defined(Q_OS_ANDROID) && (_POSIX_MONOTONIC_CLOCK-0 >= 0) +#if (_POSIX_MONOTONIC_CLOCK-0 >= 0) +#if defined(Q_OS_ANDROID) + if (local_condattr_setclock && QElapsedTimer::clockType() == QElapsedTimer::MonotonicClock) + local_condattr_setclock(&condattr, CLOCK_MONOTONIC); +#elif !defined(Q_OS_MAC) if (QElapsedTimer::clockType() == QElapsedTimer::MonotonicClock) pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC); +#endif #endif report_error(pthread_cond_init(cond, &condattr), where, "cv init"); pthread_condattr_destroy(&condattr); @@ -108,7 +116,7 @@ public: { timespec ti; #ifdef Q_OS_ANDROID - if (Q_LIKELY(local_cond_timedwait_relative)) { + if (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); -- cgit v1.2.3