179 IterateKernel(QThreadPool *pool, Iterator _begin, Iterator _end, U &&_defaultValue)
184 iterationCount(selectIteration(IteratorCategory()) ?
static_cast<
int>(
std::distance(_begin, _end)) : 0),
221 BlockSizeManager blockSizeManager(ThreadEngineBase::threadPool, iterationCount);
225 if (
this->isCanceled())
228 const int currentBlockSize = blockSizeManager.blockSize();
230 if (currentIndex.loadRelaxed() >= iterationCount)
234 const int beginIndex = currentIndex.fetchAndAddRelease(currentBlockSize);
235 const int endIndex = qMin(beginIndex + currentBlockSize,
iterationCount);
237 if (beginIndex >= endIndex) {
242 this->waitForResume();
247 const int finalBlockSize = endIndex - beginIndex;
248 resultReporter.reserveSpace(finalBlockSize);
251 blockSizeManager.timeBeforeUser();
253 blockSizeManager.timeAfterUser();
255 if (resultsAvailable)
256 resultReporter.reportResults(beginIndex);
260 completed.fetchAndAddAcquire(finalBlockSize);
261 this->setProgressValue(
this->completed.loadRelaxed());
264 if (
this->shouldThrottleThread())
265 return ThrottleThread;
267 return ThreadFinished;
272 if (iteratorThreads.testAndSetAcquire(0, 1) ==
false)
273 return ThreadFinished;
276 resultReporter.reserveSpace(1);
284 int index = currentIndex.fetchAndAddRelaxed(1);
285 iteratorThreads.testAndSetRelease(1, 0);
287 this->waitForResume();
292 const bool resultAavailable =
this->runIteration(prev
, index
, resultReporter.getPointer()
);
293 if (resultAavailable)
294 resultReporter.reportResults(index);
296 if (
this->shouldThrottleThread())
297 return ThrottleThread;
299 if (iteratorThreads.testAndSetAcquire(0, 1) ==
false)
300 return ThreadFinished;
303 return ThreadFinished;