version 3.3

VRS::MT::TaskBase Class Reference

Defines the basic interface for tasks processed in a multi threaded environment. More...

#include <vrs/mt/taskmanager.h>

Inheritance diagram for VRS::MT::TaskBase:

VRS::SharedObj VRS::Visitable VRS::MT::Task< RESULT_TYPE >

List of all members.

Public Types

enum  State {
  State_Queued, State_Running, State_Canceling, State_Finished,
  State_Canceled, State_Exception
}
 Defines the possible states of a task. More...

Public Member Functions

 VRS_TYPEINFO (TaskBase, VRS::SharedObj)
virtual State state () const
 Returns the current state of the task.
virtual bool ended () const
 Returns true if the task is in finished, canceled or exception state; otherwise false.
virtual double priority () const
 Returns the priority of the task.
virtual void changePriority (double newPriority)
 Allows to change the priority of the task.
virtual void wait () const
 If the task is in state finished, canceled or exception the call to wait() will return immediately.
virtual bool wait (double seconds) const
 If the task is in state finished, canceled or exception the call to wait() will return immediately.
virtual void cancel ()
 If the task is in queued state it will be set immediately to canceled state.
virtual ~TaskBase ()
 Virtual destructor.

Static Public Member Functions

static void Sleep (double seconds)
 Puts the current task into sleep for at least the given amount of seconds.
static void Yield ()
 Reschedules the current task.
static bool ShouldBeCanceled ()
 Tests, if the running task has been signaled for cancelation.
static void DoCancelation ()
 Performes the task cancelation (throws a corresponding exception).

Public Attributes

Impl *const m_impl

Protected Member Functions

 TaskBase (double priority, double cancelIfNotStartedWithinSecond, bool finished)
 Protected constructor.
virtual void work ()=0
 A subclass has to implement this method.
void workImpl ()
 Implements the state changes around the actual work.

Friends

class TaskManager


Detailed Description

Defines the basic interface for tasks processed in a multi threaded environment.

Member Enumeration Documentation

Defines the possible states of a task.

Enumerator:
State_Queued 
State_Running  task has not been started yet (initial state after task object creation)
State_Canceling  task is currently running
State_Finished  task has been signaled to cancel
State_Canceled  task execution has been successfully finished
State_Exception  task execution has been successfully canceled

an unhandle exception has been occured during task execution


Constructor & Destructor Documentation

VRS::MT::TaskBase::TaskBase ( double  priority,
double  cancelIfNotStartedWithinSecond,
bool  finished 
) [protected]

Protected constructor.

virtual VRS::MT::TaskBase::~TaskBase (  )  [virtual]

Virtual destructor.


Member Function Documentation

VRS::MT::TaskBase::VRS_TYPEINFO ( TaskBase  ,
VRS::SharedObj   
)

virtual State VRS::MT::TaskBase::state (  )  const [virtual]

Returns the current state of the task.

virtual bool VRS::MT::TaskBase::ended (  )  const [virtual]

Returns true if the task is in finished, canceled or exception state; otherwise false.

virtual double VRS::MT::TaskBase::priority (  )  const [virtual]

Returns the priority of the task.

virtual void VRS::MT::TaskBase::changePriority ( double  newPriority  )  [virtual]

Allows to change the priority of the task.

This method has only effect if the computation has not been started, i.e., the task is in queued state. The priority must be between 0.0 (= lowest priority) and 1.0 (highest priority).

virtual void VRS::MT::TaskBase::wait (  )  const [virtual]

If the task is in state finished, canceled or exception the call to wait() will return immediately.

Otherwise it will be waited until one of these states are reached.

virtual bool VRS::MT::TaskBase::wait ( double  seconds  )  const [virtual]

If the task is in state finished, canceled or exception the call to wait() will return immediately.

Otherwise it will be waited until one of these states are reached or the given amount of seconds has been elapsed. The return value indicates whether the waiting was successful (true), i.e., the task is not running anymore.

virtual void VRS::MT::TaskBase::cancel (  )  [virtual]

If the task is in queued state it will be set immediately to canceled state.

If the task is in running state it will be signaled, that cancelation should take place. The running task has to call cancelationPoint() in order to support cancelation. In all other cases nothing is done at all. Note: the call to cancel() is not blocking and will return immediately. If you want to wait for the cancelation of the task call wait() in addition.

static void VRS::MT::TaskBase::Sleep ( double  seconds  )  [static]

Puts the current task into sleep for at least the given amount of seconds.

static void VRS::MT::TaskBase::Yield (  )  [static]

Reschedules the current task.

static bool VRS::MT::TaskBase::ShouldBeCanceled (  )  [static]

Tests, if the running task has been signaled for cancelation.

If the current task schould be canceled (return value = true), the task should do some cleanup (if necessary) and then call DoCancelation().

static void VRS::MT::TaskBase::DoCancelation (  )  [static]

Performes the task cancelation (throws a corresponding exception).

virtual void VRS::MT::TaskBase::work (  )  [protected, pure virtual]

A subclass has to implement this method.

Implemented in VRS::MT::Task< RESULT_TYPE >.

void VRS::MT::TaskBase::workImpl (  )  [protected]

Implements the state changes around the actual work.


Friends And Related Function Documentation

friend class TaskManager [friend]

Reimplemented in VRS::MT::Task< RESULT_TYPE >.


Member Data Documentation


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

Generated on Sun May 19 06:00:48 2013 by Doxygen 1.5.6
© 2001-2010 Hasso-Plattner-Institut | Impressum | Contact