diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2016-06-06 06:30:41 -0500 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2016-09-15 19:43:57 +0000 |
commit | b630a4513c3023d0217c53638841bd06d1deda42 (patch) | |
tree | badbf4de6b709b1dc691a9eb681e7bf6cec9d863 /src/concurrent | |
parent | ec770a85305c40ba182bdc67dddcf412facbfb74 (diff) |
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 <marc.mutz@kdab.com>
Diffstat (limited to 'src/concurrent')
-rw-r--r-- | src/concurrent/concurrent.pro | 4 | ||||
-rw-r--r-- | src/concurrent/qtconcurrentiteratekernel.cpp | 75 |
2 files changed, 2 insertions, 77 deletions
diff --git a/src/concurrent/concurrent.pro b/src/concurrent/concurrent.pro index 337f4042bd..017153c74d 100644 --- a/src/concurrent/concurrent.pro +++ b/src/concurrent/concurrent.pro @@ -37,8 +37,4 @@ HEADERS += \ # private headers HEADERS += \ -qtConfig(clock-gettime) { - linux-*|hpux-*|solaris-*: LIBS_PRIVATE *= -lrt -} - load(qt_module) 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 <mach/mach.h> -#include <mach/mach_time.h> -#include <unistd.h> -#elif defined(Q_OS_UNIX) -#if defined(Q_OS_HURD) -#include <sys/time.h> -#endif -#include <time.h> -#include <unistd.h> -#elif defined(Q_OS_WIN) -#include <qt_windows.h> -#endif - +#include <qdeadlinetimer.h> #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); |