Eclipse SUMO - Simulation of Urban MObility
FXWorkerThread::Pool Class Reference

A pool of worker threads which distributes the tasks and collects the results. More...

#include <FXWorkerThread.h>

Collaboration diagram for FXWorkerThread::Pool:

Public Member Functions

void add (Task *const t, int index=-1)
 Gives a number to the given task and assigns it to the worker with the given index. If the index is negative, assign to the next (round robin) one. More...
 
void addFinished (std::list< Task * > &tasks)
 Adds the given tasks to the list of finished tasks. More...
 
void addWorker (FXWorkerThread *const w)
 Adds the given thread to the pool. More...
 
void clear ()
 Stops and deletes all worker threads. More...
 
const std::vector< FXWorkerThread * > & getWorkers ()
 
bool isFull () const
 Checks whether there are currently more pending tasks than threads. More...
 
void lock ()
 locks the pool mutex More...
 
 Pool (int numThreads=0)
 Constructor. More...
 
void setException (ProcessError &e)
 
int size () const
 Returns the number of threads in the pool. More...
 
void unlock ()
 unlocks the pool mutex More...
 
void waitAll (const bool deleteFinished=true)
 waits for all tasks to be finished More...
 
virtual ~Pool ()
 Destructor. More...
 

Private Attributes

FXCondition myCondition
 the semaphore to wait on for finishing all tasks More...
 
ProcessErrormyException
 the exception from a child thread More...
 
std::list< Task * > myFinishedTasks
 list of finished tasks More...
 
FXMutex myMutex
 the internal mutex for the task list More...
 
FXMutex myPoolMutex
 the pool mutex for external sync More...
 
int myRunningIndex
 the running index for the next task More...
 
std::vector< FXWorkerThread * > myWorkers
 the current worker threads More...
 

Detailed Description

A pool of worker threads which distributes the tasks and collects the results.

Definition at line 88 of file FXWorkerThread.h.

Constructor & Destructor Documentation

◆ Pool()

FXWorkerThread::Pool::Pool ( int  numThreads = 0)
inline

Constructor.

May initialize the pool with a given number of workers.

Parameters
[in]numThreadsthe number of threads to create

Definition at line 96 of file FXWorkerThread.h.

References FXWorkerThread::FXWorkerThread().

◆ ~Pool()

virtual FXWorkerThread::Pool::~Pool ( )
inlinevirtual

Destructor.

Stopping and deleting all workers by calling clear.

Definition at line 120 of file FXWorkerThread.h.

References clear().

Member Function Documentation

◆ add()

void FXWorkerThread::Pool::add ( Task *const  t,
int  index = -1 
)
inline

Gives a number to the given task and assigns it to the worker with the given index. If the index is negative, assign to the next (round robin) one.

Parameters
[in]tthe task to add
[in]indexindex of the worker thread to use or -1 for an arbitrary one

Definition at line 147 of file FXWorkerThread.h.

References myRunningIndex, myWorkers, and FXWorkerThread::Task::setIndex().

Referenced by LandmarkLookupTable< E, V >::LandmarkLookupTable(), and MSRoutingEngine::reroute().

Here is the caller graph for this function:

◆ addFinished()

void FXWorkerThread::Pool::addFinished ( std::list< Task * > &  tasks)
inline

Adds the given tasks to the list of finished tasks.

Locks the internal mutex and appends the finished tasks. This is to be called by the worker thread only.

Parameters
[in]tasksthe tasks to add

Definition at line 169 of file FXWorkerThread.h.

References myCondition, myFinishedTasks, and myMutex.

Referenced by FXWorkerThread::run().

Here is the caller graph for this function:

◆ addWorker()

void FXWorkerThread::Pool::addWorker ( FXWorkerThread *const  w)
inline

Adds the given thread to the pool.

Parameters
[in]wthe thread to add

Definition at line 137 of file FXWorkerThread.h.

References myWorkers.

Referenced by FXWorkerThread::FXWorkerThread().

Here is the caller graph for this function:

◆ clear()

void FXWorkerThread::Pool::clear ( )
inline

Stops and deletes all worker threads.

Definition at line 126 of file FXWorkerThread.h.

References myWorkers.

Referenced by ~Pool().

Here is the caller graph for this function:

◆ getWorkers()

const std::vector<FXWorkerThread*>& FXWorkerThread::Pool::getWorkers ( )
inline

Definition at line 257 of file FXWorkerThread.h.

References myWorkers.

Referenced by MSRoutingEngine::getRouterTT(), and MSRoutingEngine::initRouter().

Here is the caller graph for this function:

◆ isFull()

bool FXWorkerThread::Pool::isFull ( ) const
inline

Checks whether there are currently more pending tasks than threads.

This is only a rough estimate because the tasks are already assigned and there could be an idle thread even though the number of tasks is large.

Returns
whether there are enough tasks to let all threads work

Definition at line 235 of file FXWorkerThread.h.

References myFinishedTasks, myRunningIndex, and size().

◆ lock()

void FXWorkerThread::Pool::lock ( )
inline

locks the pool mutex

Definition at line 248 of file FXWorkerThread.h.

References myPoolMutex.

◆ setException()

void FXWorkerThread::Pool::setException ( ProcessError e)
inline

Definition at line 176 of file FXWorkerThread.h.

References myException, and myMutex.

Referenced by FXWorkerThread::run().

Here is the caller graph for this function:

◆ size()

int FXWorkerThread::Pool::size ( ) const
inline

Returns the number of threads in the pool.

Returns
the number of threads

Definition at line 243 of file FXWorkerThread.h.

References myWorkers.

Referenced by MSRoutingEngine::getRouterTT(), MSRoutingEngine::initRouter(), isFull(), LandmarkLookupTable< E, V >::LandmarkLookupTable(), and MSRoutingEngine::reroute().

Here is the caller graph for this function:

◆ unlock()

void FXWorkerThread::Pool::unlock ( )
inline

unlocks the pool mutex

Definition at line 253 of file FXWorkerThread.h.

References myPoolMutex.

◆ waitAll()

void FXWorkerThread::Pool::waitAll ( const bool  deleteFinished = true)
inline

waits for all tasks to be finished

Definition at line 185 of file FXWorkerThread.h.

References MAX2(), MIN2(), myCondition, myException, myFinishedTasks, myMutex, myRunningIndex, myWorkers, toString(), WORKLOAD_INTERVAL, and WRITE_MESSAGE.

Referenced by LandmarkLookupTable< E, V >::LandmarkLookupTable().

Here is the caller graph for this function:

Field Documentation

◆ myCondition

FXCondition FXWorkerThread::Pool::myCondition
private

the semaphore to wait on for finishing all tasks

Definition at line 268 of file FXWorkerThread.h.

Referenced by addFinished(), and waitAll().

◆ myException

ProcessError* FXWorkerThread::Pool::myException
private

the exception from a child thread

Definition at line 274 of file FXWorkerThread.h.

Referenced by setException(), and waitAll().

◆ myFinishedTasks

std::list<Task*> FXWorkerThread::Pool::myFinishedTasks
private

list of finished tasks

Definition at line 270 of file FXWorkerThread.h.

Referenced by addFinished(), isFull(), and waitAll().

◆ myMutex

FXMutex FXWorkerThread::Pool::myMutex
private

the internal mutex for the task list

Definition at line 264 of file FXWorkerThread.h.

Referenced by addFinished(), setException(), and waitAll().

◆ myPoolMutex

FXMutex FXWorkerThread::Pool::myPoolMutex
private

the pool mutex for external sync

Definition at line 266 of file FXWorkerThread.h.

Referenced by lock(), and unlock().

◆ myRunningIndex

int FXWorkerThread::Pool::myRunningIndex
private

the running index for the next task

Definition at line 272 of file FXWorkerThread.h.

Referenced by add(), isFull(), and waitAll().

◆ myWorkers

std::vector<FXWorkerThread*> FXWorkerThread::Pool::myWorkers
private

the current worker threads

Definition at line 262 of file FXWorkerThread.h.

Referenced by add(), addWorker(), clear(), getWorkers(), size(), and waitAll().


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