45 #include <mach/mach.h> 46 #include <mach/mach_time.h> 48 #elif defined(Q_OS_UNIX) 49 #if defined(Q_OS_HURD) 54 #elif defined(Q_OS_WIN) 58 #include "private/qfunctions_p.h" 61 #ifndef QT_NO_CONCURRENT 74 return mach_absolute_time();
77 #elif defined(Q_OS_UNIX) 82 #if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) 85 #ifndef _POSIX_THREAD_CPUTIME 86 clockId = CLOCK_REALTIME;
87 #elif (_POSIX_THREAD_CPUTIME-0 <= 0) 89 clockId = CLOCK_REALTIME;
91 # if (_POSIX_THREAD_CPUTIME-0 == 0) 93 static long useThreadCpuTime = -2;
94 if (useThreadCpuTime == -2) {
96 useThreadCpuTime = sysconf(_SC_THREAD_CPUTIME);
98 if (useThreadCpuTime != -1)
99 clockId = CLOCK_THREAD_CPUTIME_ID;
102 clockId = CLOCK_THREAD_CPUTIME_ID;
106 if (clock_gettime(clockId, &ts) == -1)
108 return (ts.tv_sec * 1000000000) + ts.tv_nsec;
116 gettimeofday(&tv, 0);
117 return (tv.tv_sec * 1000000) + tv.tv_usec;
123 #elif defined(Q_OS_WIN) 128 if (!QueryPerformanceCounter(&x))
137 return double(after - before);
147 beforeUser(0), afterUser(0),
153 void BlockSizeManager::timeBeforeUser()
155 if (blockSizeMaxed())
159 controlPartElapsed.addValue(
elapsed(beforeUser, afterUser));
164 void BlockSizeManager::timeAfterUser()
166 if (blockSizeMaxed())
170 userPartElapsed.addValue(
elapsed(afterUser, beforeUser));
172 if (controlPartElapsed.isMedianValid() ==
false)
175 if (controlPartElapsed.median() *
TargetRatio < userPartElapsed.median())
178 m_blockSize =
qMin(m_blockSize * 2, maxBlockSize);
180 #ifdef QTCONCURRENT_FOR_DEBUG 181 qDebug() <<
QThread::currentThread() <<
"adjusting block size" << controlPartElapsed.median() << userPartElapsed.median() << m_blockSize;
186 controlPartElapsed.reset();
187 userPartElapsed.reset();
199 #endif // QT_NO_CONCURRENT
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
static double elapsed(qint64 after, qint64 before)
#define QT_END_NAMESPACE
This macro expands to.
Q_CORE_EXPORT void qDebug(const char *,...)
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QtConcurrent namespace provides high-level APIs that make it possible to write multi-threaded pro...
static QThreadPool * globalInstance()
Returns the global QThreadPool instance.