RSC  0.16.0
rsc::threading::SimpleTask Class Reference

A Task subclass which maintains interruption through a volatile boolean flag which should be processed by the user code. More...

#include <SimpleTask.h>

Inheritance diagram for rsc::threading::SimpleTask:
Inheritance graph
Collaboration diagram for rsc::threading::SimpleTask:
Collaboration graph

Public Member Functions

 SimpleTask ()
 
virtual ~SimpleTask ()
 
virtual void cancel ()
 Interrupts the task as soon as possible. More...
 
virtual bool isCancelRequested ()
 Tells whether the task was interrupted by a call to cancel. More...
 
virtual void waitDone ()
 Waits for the execution of this task to finish. More...
 
virtual bool isDone ()
 Indicates whether the task finished execution, either through being canceled or through successfully ending. More...
 
- Public Member Functions inherited from rsc::threading::Task
virtual ~Task ()
 
virtual void run ()=0
 Performs the real task work. More...
 

Protected Member Functions

void markDone ()
 

Private Attributes

boost::recursive_mutex mutex
 
boost::condition condition
 
volatile bool canceled
 
volatile bool done
 

Detailed Description

A Task subclass which maintains interruption through a volatile boolean flag which should be processed by the user code.

Implementations of run must call markDone whenever they stop working. This is either because their job finished or they were canceled.

Author
jwienke

Definition at line 47 of file SimpleTask.h.

Constructor & Destructor Documentation

rsc::threading::SimpleTask::SimpleTask ( )

Definition at line 32 of file SimpleTask.cpp.

rsc::threading::SimpleTask::~SimpleTask ( )
virtual

Definition at line 36 of file SimpleTask.cpp.

Member Function Documentation

void rsc::threading::SimpleTask::cancel ( )
virtual

Interrupts the task as soon as possible.

Will, at some time, wake up waiting threads in waitDone.

Implements rsc::threading::Task.

Definition at line 39 of file SimpleTask.cpp.

References canceled, and mutex.

bool rsc::threading::SimpleTask::isCancelRequested ( )
virtual

Tells whether the task was interrupted by a call to cancel.

Returns
true if cancel was called, else false

Implements rsc::threading::Task.

Definition at line 44 of file SimpleTask.cpp.

References canceled, and mutex.

bool rsc::threading::SimpleTask::isDone ( )
virtual

Indicates whether the task finished execution, either through being canceled or through successfully ending.

If true is returned, the run method of this task will not perform anything anymore.

Returns
true if run will not perform anything anymore

Implements rsc::threading::Task.

Definition at line 64 of file SimpleTask.cpp.

References done, and mutex.

void rsc::threading::SimpleTask::markDone ( )
protected

Definition at line 56 of file SimpleTask.cpp.

References condition, done, and mutex.

void rsc::threading::SimpleTask::waitDone ( )
virtual

Waits for the execution of this task to finish.

This may either be caused by a successful completion of the task or by being canceled. This method must block until run exits or it is sure that run will not be called anymore.

Undefined behavior might occur if this method is called before the task is scheduled. I.e. a calling thread might block infinitely.

Implements rsc::threading::Task.

Definition at line 49 of file SimpleTask.cpp.

References condition, done, and mutex.

Member Data Documentation

volatile bool rsc::threading::SimpleTask::canceled
private

Definition at line 69 of file SimpleTask.h.

Referenced by cancel(), and isCancelRequested().

boost::condition rsc::threading::SimpleTask::condition
private

Definition at line 67 of file SimpleTask.h.

Referenced by markDone(), and waitDone().

volatile bool rsc::threading::SimpleTask::done
private

Definition at line 70 of file SimpleTask.h.

Referenced by isDone(), markDone(), and waitDone().

boost::recursive_mutex rsc::threading::SimpleTask::mutex
mutableprivate

Definition at line 66 of file SimpleTask.h.

Referenced by cancel(), isCancelRequested(), isDone(), markDone(), and waitDone().


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