Eclipse SUMO - Simulation of Urban MObility
|
A pool of worker threads which distributes the tasks and collects the results. More...
#include <MFXWorkerThread.h>
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. | |
void | addFinished (std::list< Task * > &tasks) |
Adds the given tasks to the list of finished tasks. | |
void | addWorker (MFXWorkerThread *const w) |
Adds the given thread to the pool. | |
void | clear () |
Stops and deletes all worker threads. | |
const std::vector< MFXWorkerThread * > & | getWorkers () |
bool | isFull () const |
Checks whether there are currently more pending tasks than threads. | |
void | lock () |
locks the pool mutex | |
Pool (int numThreads=0) | |
Constructor. | |
void | setException (ProcessError &e) |
int | size () const |
Returns the number of threads in the pool. | |
void | unlock () |
unlocks the pool mutex | |
void | waitAll (const bool deleteFinished=true) |
waits for all tasks to be finished | |
virtual | ~Pool () |
Destructor. | |
Private Attributes | |
FXCondition | myCondition |
the semaphore to wait on for finishing all tasks | |
ProcessError * | myException |
the exception from a child thread | |
std::list< Task * > | myFinishedTasks |
list of finished tasks | |
FXMutex | myMutex |
the internal mutex for the task list | |
FXMutex | myPoolMutex |
the pool mutex for external sync | |
int | myRunningIndex |
the running index for the next task | |
std::vector< MFXWorkerThread * > | myWorkers |
the current worker threads | |
A pool of worker threads which distributes the tasks and collects the results.
Definition at line 86 of file MFXWorkerThread.h.
|
inline |
Constructor.
May initialize the pool with a given number of workers.
[in] | numThreads | the number of threads to create |
Definition at line 94 of file MFXWorkerThread.h.
|
inlinevirtual |
Destructor.
Stopping and deleting all workers by calling clear.
Definition at line 118 of file MFXWorkerThread.h.
References clear().
|
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.
[in] | t | the task to add |
[in] | index | index of the worker thread to use or -1 for an arbitrary one |
Definition at line 145 of file MFXWorkerThread.h.
References myRunningIndex, myWorkers, and MFXWorkerThread::Task::setIndex().
Referenced by LandmarkLookupTable< E, V, M >::LandmarkLookupTable(), and MSRoutingEngine::reroute().
|
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.
[in] | tasks | the tasks to add |
Definition at line 167 of file MFXWorkerThread.h.
References myCondition, myFinishedTasks, and myMutex.
Referenced by MFXWorkerThread::run().
|
inline |
Adds the given thread to the pool.
[in] | w | the thread to add |
Definition at line 135 of file MFXWorkerThread.h.
References myWorkers.
Referenced by MFXWorkerThread::MFXWorkerThread().
|
inline |
Stops and deletes all worker threads.
Definition at line 124 of file MFXWorkerThread.h.
References myWorkers.
Referenced by ~Pool().
|
inline |
Definition at line 257 of file MFXWorkerThread.h.
References myWorkers.
Referenced by MSRoutingEngine::getIntermodalRouterTT(), MSRoutingEngine::getRouterTT(), and MSRoutingEngine::initRouter().
|
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.
Definition at line 235 of file MFXWorkerThread.h.
References myFinishedTasks, myRunningIndex, and size().
|
inline |
|
inline |
Definition at line 174 of file MFXWorkerThread.h.
References myException, and myMutex.
Referenced by MFXWorkerThread::run().
|
inline |
Returns the number of threads in the pool.
Definition at line 243 of file MFXWorkerThread.h.
References myWorkers.
Referenced by MSRoutingEngine::getIntermodalRouterTT(), MSRoutingEngine::getRouterTT(), MSRoutingEngine::initRouter(), isFull(), LandmarkLookupTable< E, V, M >::LandmarkLookupTable(), MSRoutingEngine::reroute(), and MSRoutingEngine::reroute().
|
inline |
|
inline |
waits for all tasks to be finished
Definition at line 183 of file MFXWorkerThread.h.
References MAX2(), MIN2(), myCondition, myException, myFinishedTasks, myMutex, myRunningIndex, myWorkers, toString(), WORKLOAD_INTERVAL, and WRITE_MESSAGE.
Referenced by LandmarkLookupTable< E, V, M >::LandmarkLookupTable().
|
private |
the semaphore to wait on for finishing all tasks
Definition at line 268 of file MFXWorkerThread.h.
Referenced by addFinished(), and waitAll().
|
private |
the exception from a child thread
Definition at line 274 of file MFXWorkerThread.h.
Referenced by setException(), and waitAll().
|
private |
list of finished tasks
Definition at line 270 of file MFXWorkerThread.h.
Referenced by addFinished(), isFull(), and waitAll().
|
private |
the internal mutex for the task list
Definition at line 264 of file MFXWorkerThread.h.
Referenced by addFinished(), setException(), and waitAll().
|
private |
the pool mutex for external sync
Definition at line 266 of file MFXWorkerThread.h.
|
private |
the running index for the next task
Definition at line 272 of file MFXWorkerThread.h.
|
private |
the current worker threads
Definition at line 262 of file MFXWorkerThread.h.
Referenced by add(), addWorker(), clear(), getWorkers(), size(), and waitAll().