180 IterateKernel(QThreadPool *pool, Iterator _begin, Iterator _end, U &&_defaultValue)
185 iterationCount(selectIteration(IteratorCategory()) ?
static_cast<
int>(
std::distance(_begin, _end)) : 0),
222 BlockSizeManager blockSizeManager(ThreadEngineBase::threadPool, iterationCount);
226 if (
this->isCanceled())
229 const int currentBlockSize = blockSizeManager.blockSize();
231 if (currentIndex.loadRelaxed() >= iterationCount)
235 const int beginIndex = currentIndex.fetchAndAddRelease(currentBlockSize);
236 const int endIndex = qMin(beginIndex + currentBlockSize,
iterationCount);
238 if (beginIndex >= endIndex) {
243 this->waitForResume();
248 const int finalBlockSize = endIndex - beginIndex;
249 resultReporter.reserveSpace(finalBlockSize);
252 blockSizeManager.timeBeforeUser();
254 blockSizeManager.timeAfterUser();
256 if (resultsAvailable)
257 resultReporter.reportResults(beginIndex);
261 completed.fetchAndAddAcquire(finalBlockSize);
262 this->setProgressValue(
this->completed.loadRelaxed());
265 if (
this->shouldThrottleThread())
266 return ThrottleThread;
268 return ThreadFinished;
273 if (iteratorThreads.testAndSetAcquire(0, 1) ==
false)
274 return ThreadFinished;
277 resultReporter.reserveSpace(1);
285 int index = currentIndex.fetchAndAddRelaxed(1);
286 iteratorThreads.testAndSetRelease(1, 0);
288 this->waitForResume();
293 const bool resultAavailable =
this->runIteration(prev
, index
, resultReporter.getPointer()
);
294 if (resultAavailable)
295 resultReporter.reportResults(index);
297 if (
this->shouldThrottleThread())
298 return ThrottleThread;
300 if (iteratorThreads.testAndSetAcquire(0, 1) ==
false)
301 return ThreadFinished;
304 return ThreadFinished;