From b630a4513c3023d0217c53638841bd06d1deda42 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 6 Jun 2016 06:30:41 -0500 Subject: QtConcurrent: use QDeadlineTimer to get the clock tick Instead of duplicating what QElapsedTimer & QDeadlineTimer already do. Well, technically speaking, we aren't getting ticks, but nanoseconds now, but the times are only used in comparisons with each other, to measure the control overhead, so the unit in which they are measured doesn't matter. This also makes all OSes use the same type of timers. There's no exception for per-thread timing. Change-Id: I115db302eb114bed8cd1fffd14557b228284f2c0 Reviewed-by: Marc Mutz --- src/concurrent/qtconcurrentiteratekernel.cpp | 75 +--------------------------- 1 file changed, 2 insertions(+), 73 deletions(-) (limited to 'src/concurrent/qtconcurrentiteratekernel.cpp') diff --git a/src/concurrent/qtconcurrentiteratekernel.cpp b/src/concurrent/qtconcurrentiteratekernel.cpp index 4b6ccc2810..52218f794b 100644 --- a/src/concurrent/qtconcurrentiteratekernel.cpp +++ b/src/concurrent/qtconcurrentiteratekernel.cpp @@ -39,20 +39,7 @@ #include "qtconcurrentiteratekernel.h" -#if defined(Q_OS_MAC) -#include -#include -#include -#elif defined(Q_OS_UNIX) -#if defined(Q_OS_HURD) -#include -#endif -#include -#include -#elif defined(Q_OS_WIN) -#include -#endif - +#include #include "private/qfunctions_p.h" @@ -65,69 +52,11 @@ enum { MedianSize = 7 }; -#if defined(Q_OS_MAC) - static qint64 getticks() { - return mach_absolute_time(); + return QDeadlineTimer::current(Qt::PreciseTimer).deadlineNSecs(); } -#elif defined(Q_OS_UNIX) - - -static qint64 getticks() -{ -#if (defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0)) || defined(Q_OS_OPENBSD) - clockid_t clockId; - -#ifndef _POSIX_THREAD_CPUTIME - clockId = CLOCK_REALTIME; -#elif (_POSIX_THREAD_CPUTIME-0 <= 0) - // if we don't have CLOCK_THREAD_CPUTIME_ID, we have to just use elapsed realtime instead - clockId = CLOCK_REALTIME; - -# if (_POSIX_THREAD_CPUTIME-0 == 0) - // detect availablility of CLOCK_THREAD_CPUTIME_ID - static QBasicAtomicInt sUseThreadCpuTime = Q_BASIC_ATOMIC_INITIALIZER(-2); - int useThreadCpuTime = sUseThreadCpuTime.load(); - if (useThreadCpuTime == -2) { - // sysconf() will return either -1L or _POSIX_VERSION - // (don't care about sysconf's exact return value) - useThreadCpuTime = sysconf(_SC_THREAD_CPUTIME) == -1L ? -1 : 0 ; - sUseThreadCpuTime.store(useThreadCpuTime); // might happen multiple times, but doesn't matter - } - if (useThreadCpuTime != -1) - clockId = CLOCK_THREAD_CPUTIME_ID; -# endif -#else - clockId = CLOCK_THREAD_CPUTIME_ID; -#endif - - struct timespec ts; - if (clock_gettime(clockId, &ts) == -1) - return 0; - return (ts.tv_sec * 1000000000) + ts.tv_nsec; -#else - - // no clock_gettime(), fall back to wall time - struct timeval tv; - gettimeofday(&tv, 0); - return (tv.tv_sec * 1000000) + tv.tv_usec; -#endif -} - -#elif defined(Q_OS_WIN) - -static qint64 getticks() -{ - LARGE_INTEGER x; - if (!QueryPerformanceCounter(&x)) - return 0; - return x.QuadPart; -} - -#endif - static double elapsed(qint64 after, qint64 before) { return double(after - before); -- cgit v1.2.3