diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2020-04-07 12:34:24 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2020-04-09 02:49:18 +0200 |
commit | b75c82f6456edbc00646da15531cfb63f8957817 (patch) | |
tree | a11709410f3e2e8f7787eaef8fe1e7f6500ab12f /src/concurrent/qtconcurrentiteratekernel.cpp | |
parent | 9ad8b80fb970cfe96c7c7bae781b20528b2ce334 (diff) |
Resolve Qt6 TODO items, replace Median and BlockSizeManager
* Replaces the, only internaly used, implementation of template
class Median with a fixed size none templated version.
* Replaces BlockSizeManager with an updated BlockSizeManager V2,
but keeping the original name.
* adapt the auto-test to take the fixed size array into account
Change-Id: If76cb944676c4a06a7566ad0bc37ded25b81c70c
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/concurrent/qtconcurrentiteratekernel.cpp')
-rw-r--r-- | src/concurrent/qtconcurrentiteratekernel.cpp | 74 |
1 files changed, 4 insertions, 70 deletions
diff --git a/src/concurrent/qtconcurrentiteratekernel.cpp b/src/concurrent/qtconcurrentiteratekernel.cpp index b65f712547..45b54ecfdc 100644 --- a/src/concurrent/qtconcurrentiteratekernel.cpp +++ b/src/concurrent/qtconcurrentiteratekernel.cpp @@ -48,8 +48,7 @@ QT_BEGIN_NAMESPACE enum { - TargetRatio = 100, - MedianSize = 7 + TargetRatio = 100 }; static qint64 getticks() @@ -71,24 +70,12 @@ namespace QtConcurrent { */ /*! - \class QtConcurrent::MedianDouble - \inmodule QtConcurrent - \internal - */ - -/*! \class QtConcurrent::BlockSizeManager \inmodule QtConcurrent \internal */ /*! - \class QtConcurrent::BlockSizeManagerV2 - \inmodule QtConcurrent - \internal - */ - -/*! \class QtConcurrent::ResultReporter \inmodule QtConcurrent \internal @@ -116,66 +103,13 @@ namespace QtConcurrent { */ BlockSizeManager::BlockSizeManager(int iterationCount) -: maxBlockSize(iterationCount / (QThreadPool::globalInstance()->maxThreadCount() * 2)), - beforeUser(0), afterUser(0), - controlPartElapsed(MedianSize), userPartElapsed(MedianSize), - m_blockSize(1) -{ } - -// Records the time before user code. -void BlockSizeManager::timeBeforeUser() -{ - if (blockSizeMaxed()) - return; - - beforeUser = getticks(); - controlPartElapsed.addValue(elapsed(beforeUser, afterUser)); -} - - // Records the time after user code and adjust the block size if we are spending - // to much time in the for control code compared with the user code. -void BlockSizeManager::timeAfterUser() -{ - if (blockSizeMaxed()) - return; - - afterUser = getticks(); - userPartElapsed.addValue(elapsed(afterUser, beforeUser)); - - if (controlPartElapsed.isMedianValid() == false) - return; - - if (controlPartElapsed.median() * TargetRatio < userPartElapsed.median()) - return; - - m_blockSize = qMin(m_blockSize * 2, maxBlockSize); - -#ifdef QTCONCURRENT_FOR_DEBUG - qDebug() << QThread::currentThread() << "adjusting block size" << controlPartElapsed.median() << userPartElapsed.median() << m_blockSize; -#endif - - // Reset the medians after adjusting the block size so we get - // new measurements with the new block size. - controlPartElapsed.reset(); - userPartElapsed.reset(); -} - -int BlockSizeManager::blockSize() -{ - return m_blockSize; -} - -/*! \internal - -*/ -BlockSizeManagerV2::BlockSizeManagerV2(int iterationCount) : maxBlockSize(iterationCount / (QThreadPool::globalInstance()->maxThreadCount() * 2)), beforeUser(0), afterUser(0), m_blockSize(1) { } // Records the time before user code. -void BlockSizeManagerV2::timeBeforeUser() +void BlockSizeManager::timeBeforeUser() { if (blockSizeMaxed()) return; @@ -186,7 +120,7 @@ void BlockSizeManagerV2::timeBeforeUser() // Records the time after user code and adjust the block size if we are spending // to much time in the for control code compared with the user code. -void BlockSizeManagerV2::timeAfterUser() +void BlockSizeManager::timeAfterUser() { if (blockSizeMaxed()) return; @@ -212,7 +146,7 @@ void BlockSizeManagerV2::timeAfterUser() userPartElapsed.reset(); } -int BlockSizeManagerV2::blockSize() +int BlockSizeManager::blockSize() { return m_blockSize; } |