From b75c82f6456edbc00646da15531cfb63f8957817 Mon Sep 17 00:00:00 2001 From: Karsten Heimrich Date: Tue, 7 Apr 2020 12:34:24 +0200 Subject: 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 --- src/concurrent/qtconcurrentiteratekernel.cpp | 74 ++-------------------------- 1 file changed, 4 insertions(+), 70 deletions(-) (limited to 'src/concurrent/qtconcurrentiteratekernel.cpp') 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() @@ -70,24 +69,12 @@ namespace QtConcurrent { \internal */ -/*! - \class QtConcurrent::MedianDouble - \inmodule QtConcurrent - \internal - */ - /*! \class QtConcurrent::BlockSizeManager \inmodule QtConcurrent \internal */ -/*! - \class QtConcurrent::BlockSizeManagerV2 - \inmodule QtConcurrent - \internal - */ - /*! \class QtConcurrent::ResultReporter \inmodule QtConcurrent @@ -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; } -- cgit v1.2.3