RSC
0.17.1
|
A task that already provides a base frame for common logic of interruptible tasks. More...
#include <RepetitiveTask.h>
Public Member Functions | |
RepetitiveTask () | |
virtual | ~RepetitiveTask () |
virtual void | pre () |
A method called before each iteration of the task. More... | |
virtual void | execute ()=0 |
This method is invoked to perform the real work of the task. More... | |
virtual void | post () |
A method called after each iteration of the task. More... | |
virtual void | cancel () |
Interrupts the task. More... | |
virtual bool | isCancelRequested () |
Tells whether the task was interrupted by a call to cancel. More... | |
virtual bool | continueExec () |
Tells whether the #exec method shall be called another time. More... | |
void | run () |
Performs the real task work orchestrating the iterative loop with the different hook methods and so on. 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 () |
Protected Attributes | |
boost::recursive_mutex | doneMutex |
boost::condition | doneCondition |
Private Member Functions | |
void | markDone () |
void | timerBeforeCycle () |
void | timerAfterCycle () |
Private Attributes | |
volatile bool | cancelRequest |
volatile bool | done |
rsc::logging::LoggerPtr | logger |
boost::timer | timer |
Friends | |
std::ostream & | operator<< (std::ostream &out, const RepetitiveTask &t) |
A task that already provides a base frame for common logic of interruptible tasks.
This is a loop that executes at least once. More times are possible if continueExec returns true after a loop. This is a common pattern for interruptible tasks.
In each iteration for a task, first a hook is called before the real work (pre), then the real work in that iteration is executed with #exec, and afterwards a post hook (post) is called. If another iteration shall be performed, continueExec has to return true
(defaults to false
).
A default flag mechanism to cancel a task is provided and incorporated into continueExec.
Definition at line 59 of file RepetitiveTask.h.
rsc::threading::RepetitiveTask::RepetitiveTask | ( | ) |
Definition at line 34 of file RepetitiveTask.cpp.
|
virtual |
Definition at line 39 of file RepetitiveTask.cpp.
|
virtual |
Interrupts the task.
The default implementation sets a boolean flag that can be checked with isCancelRequested.
Implements rsc::threading::Task.
Definition at line 50 of file RepetitiveTask.cpp.
References cancelRequest.
|
virtual |
Tells whether the #exec method shall be called another time.
Do not forget to incorporate the cancel mechanism while overriding this method if the #exec method does not do this itself.
true
of iterations of #exec calls shall continue, else false
, default implementation returns true
unless the task is canceled. Reimplemented in rsc::threading::PeriodicTask.
Definition at line 58 of file RepetitiveTask.cpp.
References isCancelRequested().
Referenced by run().
|
pure virtual |
This method is invoked to perform the real work of the task.
Referenced by run().
|
virtual |
Tells whether the task was interrupted by a call to cancel.
The default implementation returns the value of a boolean flag. Override this for more complex logic but don't forget to also override cancel then.
true
if cancel was called, else false
Implements rsc::threading::Task.
Definition at line 54 of file RepetitiveTask.cpp.
References cancelRequest.
Referenced by rsc::threading::PeriodicTask::continueExec(), continueExec(), and run().
|
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.
true
if run will not perform anything anymore Implements rsc::threading::Task.
Definition at line 108 of file RepetitiveTask.cpp.
References done.
|
private |
Definition at line 92 of file RepetitiveTask.cpp.
References done, doneCondition, and doneMutex.
Referenced by run().
|
virtual |
A method called after each iteration of the task.
The default methods logs timing information. Use it for comparable tasks only.
Definition at line 46 of file RepetitiveTask.cpp.
References timerAfterCycle().
Referenced by run().
|
virtual |
A method called before each iteration of the task.
The default implementation starts a timer for performance measurements. Override this for comparable tasks.
Definition at line 42 of file RepetitiveTask.cpp.
References timerBeforeCycle().
Referenced by run().
|
virtual |
Performs the real task work orchestrating the iterative loop with the different hook methods and so on.
Implements rsc::threading::Task.
Definition at line 62 of file RepetitiveTask.cpp.
References continueExec(), execute(), isCancelRequested(), logger, markDone(), post(), pre(), RSCDEBUG, and RSCTRACE.
|
private |
|
private |
Definition at line 112 of file RepetitiveTask.cpp.
References timer.
Referenced by pre().
|
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 98 of file RepetitiveTask.cpp.
References done, doneCondition, doneMutex, logger, and RSCDEBUG.
|
friend |
Definition at line 121 of file RepetitiveTask.cpp.
|
private |
Definition at line 134 of file RepetitiveTask.h.
Referenced by cancel(), isCancelRequested(), and rsc::threading::operator<<().
|
private |
Definition at line 135 of file RepetitiveTask.h.
Referenced by isDone(), markDone(), and waitDone().
|
protected |
Definition at line 124 of file RepetitiveTask.h.
Referenced by markDone(), and waitDone().
|
mutableprotected |
Definition at line 123 of file RepetitiveTask.h.
Referenced by markDone(), and waitDone().
|
private |
Definition at line 137 of file RepetitiveTask.h.
Referenced by run(), timerAfterCycle(), and waitDone().
|
private |
Definition at line 139 of file RepetitiveTask.h.
Referenced by timerAfterCycle(), and timerBeforeCycle().