cartobase  4.5.0
carto::ThreadedLoop Class Reference

#include <cartobase/thread/threadedLoop.h>

Public Member Functions

 ThreadedLoop (LoopContext *loopContext, int startIndex, int count, int maxThreadCount=0, float threadsByCpu=1.0f)
 
virtual ~ThreadedLoop ()
 
void setLoopContext (LoopContext *)
 This function is only useful in multiple run mode (endThreadsWhenDone false). More...
 
bool launch (bool resetGauge=true, bool resetCancel=true)
 
void run ()
 
void setEndThreadsWhenDone (bool x)
 Warning: it's possibly not safe to change this value from false to true after launch() has been called. More...
 
bool endThreadsWhenDone () const
 The loop can work in two modes: single run (endThreadsWhenDone() is true) or multiple runs (endThreadsWhenDone is false). More...
 
void setLoopCount (int n)
 

Detailed Description

Definition at line 48 of file threadedLoop.h.

Constructor & Destructor Documentation

carto::ThreadedLoop::ThreadedLoop ( LoopContext loopContext,
int  startIndex,
int  count,
int  maxThreadCount = 0,
float  threadsByCpu = 1.0f 
)
virtual carto::ThreadedLoop::~ThreadedLoop ( )
virtual

Member Function Documentation

bool carto::ThreadedLoop::endThreadsWhenDone ( ) const

The loop can work in two modes: single run (endThreadsWhenDone() is true) or multiple runs (endThreadsWhenDone is false).

  • In single run mode, launch() creates the needed number of threads, runs them to complete the loop, then destroys every thread.
  • In multiple runs mode, the first call to launch() creates the needed threads, but doesn't destroy them after the loop is finished. Each thread stays alive and blocks on a semaphore. When you call launch() again later for another run (possibly after changing the LoopContext), the existing threads will be re-used for the next loop, so the cost of destroying and creating threads again is avoided. All threads will be actually destroyed when the ThreadedLoop is deleted.
bool carto::ThreadedLoop::launch ( bool  resetGauge = true,
bool  resetCancel = true 
)
void carto::ThreadedLoop::run ( )
void carto::ThreadedLoop::setEndThreadsWhenDone ( bool  x)

Warning: it's possibly not safe to change this value from false to true after launch() has been called.

void carto::ThreadedLoop::setLoopContext ( LoopContext )

This function is only useful in multiple run mode (endThreadsWhenDone false).

Call it only between two runs, from the control thread (the thread running the loop).

void carto::ThreadedLoop::setLoopCount ( int  n)

The documentation for this class was generated from the following file: