![]() |
Eclipse SUMO - Simulation of Urban MObility
|
A pool of worker threads which distributes the tasks and collects the results. More...
#include <FXWorkerThread.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. 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... | |
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... | |
ProcessError * | myException |
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... | |
A pool of worker threads which distributes the tasks and collects the results.
Definition at line 89 of file FXWorkerThread.h.
|
inline |
Constructor.
May initialize the pool with a given number of workers.
[in] | numThreads | the number of threads to create |
Definition at line 97 of file FXWorkerThread.h.
References FXWorkerThread::FXWorkerThread().
|
inlinevirtual |
Destructor.
Stopping and deleting all workers by calling clear.
Definition at line 121 of file FXWorkerThread.h.
|
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 148 of file FXWorkerThread.h.
References FXWorkerThread::Task::setIndex().
Referenced by LandmarkLookupTable< E, V >::LandmarkLookupTable().
|
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 170 of file FXWorkerThread.h.
References FXWorkerThread::myCondition, and FXWorkerThread::myMutex.
Referenced by FXWorkerThread::run().
|
inline |
Adds the given thread to the pool.
[in] | w | the thread to add |
Definition at line 138 of file FXWorkerThread.h.
Referenced by FXWorkerThread::FXWorkerThread().
|
inline |
Stops and deletes all worker threads.
Definition at line 127 of file FXWorkerThread.h.
|
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 236 of file FXWorkerThread.h.
|
inline |
locks the pool mutex
Definition at line 249 of file FXWorkerThread.h.
|
inline |
Definition at line 177 of file FXWorkerThread.h.
References FXWorkerThread::myMutex.
Referenced by FXWorkerThread::run().
|
inline |
Returns the number of threads in the pool.
Definition at line 244 of file FXWorkerThread.h.
Referenced by LandmarkLookupTable< E, V >::LandmarkLookupTable().
|
inline |
unlocks the pool mutex
Definition at line 254 of file FXWorkerThread.h.
|
inline |
waits for all tasks to be finished
Definition at line 186 of file FXWorkerThread.h.
References MAX2(), MIN2(), FXWorkerThread::myCondition, FXWorkerThread::myMutex, toString(), WORKLOAD_INTERVAL, and WRITE_MESSAGE.
Referenced by LandmarkLookupTable< E, V >::LandmarkLookupTable().
|
private |
the semaphore to wait on for finishing all tasks
Definition at line 266 of file FXWorkerThread.h.
|
private |
the exception from a child thread
Definition at line 272 of file FXWorkerThread.h.
|
private |
list of finished tasks
Definition at line 268 of file FXWorkerThread.h.
|
private |
the internal mutex for the task list
Definition at line 262 of file FXWorkerThread.h.
|
private |
the pool mutex for external sync
Definition at line 264 of file FXWorkerThread.h.
|
private |
the running index for the next task
Definition at line 270 of file FXWorkerThread.h.
|
private |
the current worker threads
Definition at line 260 of file FXWorkerThread.h.