diff options
author | Morten Sørvig <msorvig@trolltech.com> | 2009-03-26 12:27:21 (GMT) |
---|---|---|
committer | Morten Sørvig <msorvig@trolltech.com> | 2009-03-26 12:27:21 (GMT) |
commit | b641daa11d579f58468be7f30042a100d8c483c5 (patch) | |
tree | ae6e85b2712bf93f5c0653b13ac3bfa2f016172d /src/corelib | |
parent | c48326d14d4fe8de5e11d977a30c04fd8a9aeb27 (diff) | |
download | Qt-b641daa11d579f58468be7f30042a100d8c483c5.zip Qt-b641daa11d579f58468be7f30042a100d8c483c5.tar.gz Qt-b641daa11d579f58468be7f30042a100d8c483c5.tar.bz2 |
Reduce the number of calls to QThread::idealThreadCount() in QtConcurrent.
This results in a syscall and is very slow. Make the call once and cache
the value.
Task-number: 244718
Reviewed-by: TrustMe
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/concurrent/qtconcurrentreducekernel.h | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/corelib/concurrent/qtconcurrentreducekernel.h b/src/corelib/concurrent/qtconcurrentreducekernel.h index e863b63..2dad519 100644 --- a/src/corelib/concurrent/qtconcurrentreducekernel.h +++ b/src/corelib/concurrent/qtconcurrentreducekernel.h @@ -51,6 +51,7 @@ #include <QtCore/qmap.h> #include <QtCore/qmutex.h> #include <QtCore/qthread.h> +#include <QtCore/qthreadpool.h> #include <QtCore/qvector.h> QT_BEGIN_HEADER @@ -107,7 +108,7 @@ class ReduceKernel const ReduceOptions reduceOptions; QMutex mutex; - int progress, resultsMapSize; + int progress, resultsMapSize, threadCount; ResultsMap resultsMap; bool canReduce(int begin) const @@ -140,7 +141,8 @@ class ReduceKernel public: ReduceKernel(ReduceOptions _reduceOptions) - : reduceOptions(_reduceOptions), progress(0), resultsMapSize(0) + : reduceOptions(_reduceOptions), progress(0), resultsMapSize(0), + threadCount(QThreadPool::globalInstance()->maxThreadCount()) { } void runReduce(ReduceFunctor &reduce, @@ -210,12 +212,12 @@ public: inline bool shouldThrottle() { - return (resultsMapSize > (ReduceQueueThrottleLimit * QThread::idealThreadCount())); + return (resultsMapSize > (ReduceQueueThrottleLimit * threadCount)); } inline bool shouldStartThread() { - return (resultsMapSize <= (ReduceQueueStartLimit * QThread::idealThreadCount())); + return (resultsMapSize <= (ReduceQueueStartLimit * threadCount)); } }; |