Definition at line 178 of file qtconcurrentiteratekernel.h.
#include <qtconcurrentiteratekernel.h>

Public Types |
|
| typedef T | ResultType |
Public Member Functions |
|
| IterateKernel (Iterator _begin, Iterator _end) | |
| virtual | ~IterateKernel () |
| virtual bool | runIteration (Iterator it, int index, T *result) |
| virtual bool | runIterations (Iterator _begin, int beginIndex, int endIndex, T *results) |
| void | start () |
| bool | shouldStartThread () |
| ThreadFunctionResult | threadFunction () |
| ThreadFunctionResult | forThreadFunction () |
| ThreadFunctionResult | whileThreadFunction () |
Public Attributes |
|
| const Iterator | begin |
| const Iterator | end |
| Iterator | current |
| QAtomicInt | currentIndex |
| bool | forIteration |
| QAtomicInt | iteratorThreads |
| int | iterationCount |
| bool | progressReportingEnabled |
| QAtomicInt | completed |
| typedef T ResultType |
Reimplemented from ThreadEngine< T >.
Reimplemented in FilterKernel< Sequence, KeepFunctor, ReduceFunctor >, FilteredReducedKernel< ReducedResultType, Iterator, KeepFunctor, ReduceFunctor, Reducer >, FilteredEachKernel< Iterator, KeepFunctor >, MappedReducedKernel< ReducedResultType, Iterator, MapFunctor, ReduceFunctor, Reducer >, and MappedEachKernel< Iterator, MapFunctor >.
Definition at line 181 of file qtconcurrentiteratekernel.h.
| IterateKernel | ( | Iterator | _begin, |
| Iterator | _end | ||
| ) | [inline] |
Definition at line 183 of file qtconcurrentiteratekernel.h.
: begin(_begin), end(_end), current(_begin), currentIndex(0),
forIteration(false), progressReportingEnabled(true)
#elif !defined(QT_NO_PARTIAL_TEMPLATE_SPECIALIZATION)
: begin(_begin), end(_end), current(_begin), currentIndex(0),
forIteration(selectIteration(typename std::iterator_traits<Iterator>::iterator_category())), progressReportingEnabled(true)
#else
: begin(_begin), end(_end), currentIndex(0),
forIteration(selectIteration(std::iterator_category(_begin))), progressReportingEnabled(true)
#endif
{
#if defined (QT_NO_STL)
iterationCount = 0;
#else
iterationCount = forIteration ? std::distance(_begin, _end) : 0;
#endif
}
| virtual ~IterateKernel | ( | ) | [inline, virtual] |
Definition at line 203 of file qtconcurrentiteratekernel.h.
{ }
| virtual bool runIteration | ( | Iterator | it, |
| int | index, | ||
| T * | result | ||
| ) | [inline, virtual] |
Reimplemented in FilteredReducedKernel< ReducedResultType, Iterator, KeepFunctor, ReduceFunctor, Reducer >, MapKernel< Iterator, MapFunctor >, MappedReducedKernel< ReducedResultType, Iterator, MapFunctor, ReduceFunctor, Reducer >, and MappedEachKernel< Iterator, MapFunctor >.
Definition at line 205 of file qtconcurrentiteratekernel.h.
{ Q_UNUSED(it); Q_UNUSED(index); Q_UNUSED(result); return false; }
| virtual bool runIterations | ( | Iterator | _begin, |
| int | beginIndex, | ||
| int | endIndex, | ||
| T * | results | ||
| ) | [inline, virtual] |
Reimplemented in FilteredReducedKernel< ReducedResultType, Iterator, KeepFunctor, ReduceFunctor, Reducer >, MapKernel< Iterator, MapFunctor >, MappedReducedKernel< ReducedResultType, Iterator, MapFunctor, ReduceFunctor, Reducer >, and MappedEachKernel< Iterator, MapFunctor >.
Definition at line 207 of file qtconcurrentiteratekernel.h.
{ Q_UNUSED(_begin); Q_UNUSED(beginIndex); Q_UNUSED(endIndex); Q_UNUSED(results); return false; }
| void start | ( | ) | [inline, virtual] |
Reimplemented from ThreadEngineBase.
Reimplemented in FilteredEachKernel< Iterator, KeepFunctor >.
Definition at line 210 of file qtconcurrentiteratekernel.h.
{
progressReportingEnabled = this->isProgressReportingEnabled();
if (progressReportingEnabled && iterationCount > 0)
this->setProgressRange(0, iterationCount);
}
| bool shouldStartThread | ( | ) | [inline, virtual] |
Reimplemented from ThreadEngineBase.
Reimplemented in FilterKernel< Sequence, KeepFunctor, ReduceFunctor >, FilteredReducedKernel< ReducedResultType, Iterator, KeepFunctor, ReduceFunctor, Reducer >, and MappedReducedKernel< ReducedResultType, Iterator, MapFunctor, ReduceFunctor, Reducer >.
Definition at line 217 of file qtconcurrentiteratekernel.h.
{
if (forIteration)
return (currentIndex < iterationCount) && !this->shouldThrottleThread();
else // whileIteration
return (iteratorThreads == 0);
}
| ThreadFunctionResult threadFunction | ( | ) | [inline, virtual] |
Reimplemented from ThreadEngineBase.
Definition at line 225 of file qtconcurrentiteratekernel.h.
{
if (forIteration)
return this->forThreadFunction();
else // whileIteration
return this->whileThreadFunction();
}
| ThreadFunctionResult forThreadFunction | ( | ) | [inline] |
Definition at line 233 of file qtconcurrentiteratekernel.h.
{
BlockSizeManager blockSizeManager(iterationCount);
ResultReporter<T> resultReporter(this);
for(;;) {
if (this->isCanceled())
break;
const int currentBlockSize = blockSizeManager.blockSize();
if (currentIndex >= iterationCount)
break;
// Atomically reserve a block of iterationCount for this thread.
const int beginIndex = currentIndex.fetchAndAddRelease(currentBlockSize);
const int endIndex = qMin(beginIndex + currentBlockSize, iterationCount);
if (beginIndex >= endIndex) {
// No more work
break;
}
this->waitForResume(); // (only waits if the qfuture is paused.)
if (shouldStartThread())
this->startThread();
const int finalBlockSize = endIndex - beginIndex; // block size adjusted for possible end-of-range
resultReporter.reserveSpace(finalBlockSize);
// Call user code with the current iteration range.
blockSizeManager.timeBeforeUser();
const bool resultsAvailable = this->runIterations(begin, beginIndex, endIndex, resultReporter.getPointer());
blockSizeManager.timeAfterUser();
if (resultsAvailable)
resultReporter.reportResults(beginIndex);
// Report progress if progress reporting enabled.
if (progressReportingEnabled) {
completed.fetchAndAddAcquire(finalBlockSize);
this->setProgressValue(this->completed);
}
if (this->shouldThrottleThread())
return ThrottleThread;
}
return ThreadFinished;
}
| ThreadFunctionResult whileThreadFunction | ( | ) | [inline] |
Definition at line 284 of file qtconcurrentiteratekernel.h.
{
if (iteratorThreads.testAndSetAcquire(0, 1) == false)
return ThreadFinished;
ResultReporter<T> resultReporter(this);
resultReporter.reserveSpace(1);
while (current != end) {
// The following two lines breaks support for input iterators according to
// the sgi docs: dereferencing prev after calling ++current is not allowed
// on input iterators. (prev is dereferenced inside user.runIteration())
Iterator prev = current;
++current;
int index = currentIndex.fetchAndAddRelaxed(1);
iteratorThreads.testAndSetRelease(1, 0);
this->waitForResume(); // (only waits if the qfuture is paused.)
if (shouldStartThread())
this->startThread();
const bool resultAavailable = this->runIteration(prev, index, resultReporter.getPointer());
if (resultAavailable)
resultReporter.reportResults(index);
if (this->shouldThrottleThread())
return ThrottleThread;
if (iteratorThreads.testAndSetAcquire(0, 1) == false)
return ThreadFinished;
}
return ThreadFinished;
}
| const Iterator begin |
Definition at line 322 of file qtconcurrentiteratekernel.h.
| const Iterator end |
Definition at line 323 of file qtconcurrentiteratekernel.h.
| Iterator current |
Definition at line 324 of file qtconcurrentiteratekernel.h.
Definition at line 325 of file qtconcurrentiteratekernel.h.
| bool forIteration |
Definition at line 326 of file qtconcurrentiteratekernel.h.
Definition at line 327 of file qtconcurrentiteratekernel.h.
| int iterationCount |
Definition at line 328 of file qtconcurrentiteratekernel.h.
Definition at line 330 of file qtconcurrentiteratekernel.h.
Definition at line 331 of file qtconcurrentiteratekernel.h.