Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MFXWorkerThread Class Reference

A thread repeatingly calculating incoming tasks. More...

#include <MFXWorkerThread.h>

Inheritance diagram for MFXWorkerThread:
[legend]
Collaboration diagram for MFXWorkerThread:
[legend]

Data Structures

class  Pool
 A pool of worker threads which distributes the tasks and collects the results. More...
 
class  Task
 Abstract superclass of a task to be run with an index to keep track of pending tasks. More...
 

Public Member Functions

void add (Task *t)
 Adds the given task to this thread to be calculated.
 
 MFXWorkerThread (Pool &pool)
 Constructor.
 
FXint run ()
 Main execution method of this thread.
 
void stop ()
 Stops the thread.
 
virtual ~MFXWorkerThread ()
 Destructor.
 

Private Attributes

FXCondition myCondition
 the semaphore when waiting for new tasks
 
std::list< Task * > myCurrentTasks
 the list of tasks which are currently calculated
 
FXMutex myMutex
 the mutex for the task list
 
PoolmyPool
 the pool for this thread
 
bool myStopped
 whether we are still running
 
std::list< Task * > myTasks
 the list of pending tasks
 

Detailed Description

A thread repeatingly calculating incoming tasks.

Definition at line 46 of file MFXWorkerThread.h.

Constructor & Destructor Documentation

◆ MFXWorkerThread()

MFXWorkerThread::MFXWorkerThread ( Pool pool)
inline

Constructor.

Adds the thread to the given pool and starts it.

Parameters
[in]poolthe pool for this thread

Definition at line 294 of file MFXWorkerThread.h.

References MFXWorkerThread::Pool::addWorker().

◆ ~MFXWorkerThread()

virtual MFXWorkerThread::~MFXWorkerThread ( )
inlinevirtual

Destructor.

Stops the thread by calling stop.

Definition at line 307 of file MFXWorkerThread.h.

References stop(), toString(), and WRITE_MESSAGE.

Member Function Documentation

◆ add()

void MFXWorkerThread::add ( Task t)
inline

Adds the given task to this thread to be calculated.

Parameters
[in]tthe task to add

Definition at line 321 of file MFXWorkerThread.h.

References myCondition, myMutex, and myTasks.

◆ run()

FXint MFXWorkerThread::run ( )
inline

Main execution method of this thread.

Checks for new tasks, calculates them and puts them in the finished list of the pool until being stopped.

Returns
always 0

Definition at line 334 of file MFXWorkerThread.h.

References MFXWorkerThread::Pool::addFinished(), myCondition, myCurrentTasks, myMutex, myPool, myStopped, myTasks, and MFXWorkerThread::Pool::setException().

◆ stop()

void MFXWorkerThread::stop ( )
inline

Stops the thread.

The currently running task will be finished but all further tasks are discarded.

Definition at line 370 of file MFXWorkerThread.h.

References myCondition, myMutex, and myStopped.

Referenced by ~MFXWorkerThread().

Here is the caller graph for this function:

Field Documentation

◆ myCondition

FXCondition MFXWorkerThread::myCondition
private

the semaphore when waiting for new tasks

Definition at line 396 of file MFXWorkerThread.h.

Referenced by add(), run(), and stop().

◆ myCurrentTasks

std::list<Task*> MFXWorkerThread::myCurrentTasks
private

the list of tasks which are currently calculated

Definition at line 400 of file MFXWorkerThread.h.

Referenced by run().

◆ myMutex

FXMutex MFXWorkerThread::myMutex
private

the mutex for the task list

Definition at line 394 of file MFXWorkerThread.h.

Referenced by add(), run(), and stop().

◆ myPool

Pool& MFXWorkerThread::myPool
private

the pool for this thread

Definition at line 392 of file MFXWorkerThread.h.

Referenced by run().

◆ myStopped

bool MFXWorkerThread::myStopped
private

whether we are still running

Definition at line 402 of file MFXWorkerThread.h.

Referenced by run(), and stop().

◆ myTasks

std::list<Task*> MFXWorkerThread::myTasks
private

the list of pending tasks

Definition at line 398 of file MFXWorkerThread.h.

Referenced by add(), and run().


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