Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Phx::Clock::Task Class Reference

A Task is an interface to a Clock that allows you to schedule a callback based on the Clock. More...

#include <PhxClock.h>

Inheritance diagram for Phx::Clock::Task:

Phx::LockedPtrInterface< Clock::Task > List of all members.

Public Member Functions

virtual double nextTime (void) const =0
 Returns the next time at which the task will invoke the installed listener.
virtual void nextTime (double nextTime)=0
 Sets the next time at which this task will be called back by the clock.
virtual double time (void) const =0
 Retrieves the current reported time of the Clock to which this task is attached.
virtual void listener (Listener *listener)=0
 Sets the listener that this Task will call back when its parent clock reaches time().
virtual String name (void) const =0
 Returns the name of this task, as specified in the call to Clock::newTask().
virtual void affinity (uint32_t affinity)=0
 Sets the affinity for this Task.
virtual uint32_t affinity (void) const =0
 Returns the current affinity for this Task.

Static Public Attributes

static const uint32_t AFFINITY_NONE
 A constant for the affinity() attribute that specifies the task has no affinity for a particular thread.
static const uint32_t AFFINITY_MAIN_THREAD
 A constant for the affinity() attribute that specifies the task has affinity for the main thread.
static const double NEVER
 A constant that indicates that a task as not scheduled to run again.

Classes

class  Listener
 A listener type which can be called back by the Clock task. More...

Detailed Description

A Task is an interface to a Clock that allows you to schedule a callback based on the Clock.

The client can install a Task::Listener into a Task interface. When the time() attribute of the Clock this Task is attached to is greater or equal to the Task's nextTime() attribute, the listener installed in the task will have its onTimeout method invoked.


Member Function Documentation

virtual uint32_t Phx::Clock::Task::affinity void   )  const [pure virtual]
 

Returns the current affinity for this Task.

The default is AFFINITY_NONE, specifying that this task may run on any thread. This is the most efficient setting if no particular thread needed.

virtual void Phx::Clock::Task::affinity uint32_t  affinity  )  [pure virtual]
 

Sets the affinity for this Task.

The affinity of a task specifies to the scheduler that the Task should be run on a particular thread. Thread 0 is the main thread, while threads 1..N-1 are the N-1 worker threads. If affinity is greater than N-1, the task will have an affinity for thread (affinity % N). Passing AFFINITY_NONE will allow the task to run on any thread.

Parameters:
affinity An index specifying what thread this task prefers to run on.

virtual void Phx::Clock::Task::nextTime double  nextTime  )  [pure virtual]
 

Sets the next time at which this task will be called back by the clock.

Parameters:
nextTime The next time, in terms of the underlying Clock, that this Task's listener should be called back. If nextTime <= time() (the current time of the underlying clock) then the callback will happen immediately, and the nextTime() attribute will be automatically changed to NEVER (indicating that the callback is in flight and the "next time" at which the the listener will be called is now NEVER).
This attribute is idempotent, though it may not appear so to the client.
 task->nextTime(0); // schedule listener call immediately.
 task->nextTime(0); // schedules another listener call.
 // Did this break idempotence?
This occurs because the nextTime() attribute is set to NEVER as described above. Subsequently setting nextTime() causes the task to schedule an additional callback. You can view the code above as equivalently being:
 task->nextTime(0); // schedule listener call immediately.
 // nextTime() == NEVER now because @p nextTime < time()
 // in the above call.

 task->nextTime(Clock::Task::NEVER);
 // this does nothing by idempotence with respect to the above.

 task->nextTime(0); // changes nextTime() to 0 from NEVER
 // nextTime() == NEVER again.

Certainly, the following is idempotent in the usual sense -- nothing is atypical if nextTime > time().

 // Assume:  later > task->time() for duration of this code.
 task->nextTime(later); //fine: task->nextTime() == later
 task->nextTime(later); //does nothing, by idempotence.
 task->nextTime(Clock::Task::NEVER); // Cancels call.
 // listener has not been invoked by this point and is not
 // scheduled to be invoked.

virtual double Phx::Clock::Task::nextTime void   )  const [pure virtual]
 

Returns the next time at which the task will invoke the installed listener.

The time is based on the underlying Clock for this Task. The nextTime() attribute is set to NEVER if the next pending listener invocation is not scheduled for a finite time later than time(). Put another way, NEVER is the time at which the next callback will occur once all callbacks prior or at the present time have been dispatched (which means they are in the process of being called, even though the actual function call may not yet have been made).

A simple consequence of this behavior is that nextTime() > time() at every instant.

Returns:
The next time at which the installed listener will be invoked (which may be NEVER).

virtual double Phx::Clock::Task::time void   )  const [pure virtual]
 

Retrieves the current reported time of the Clock to which this task is attached.

Returns:
The Clock::time() attribute of the Clock this Task belongs to.


Member Data Documentation

const uint32_t Phx::Clock::Task::AFFINITY_MAIN_THREAD [static]
 

A constant for the affinity() attribute that specifies the task has affinity for the main thread.

This constant is guaranteed to be 0, and may be used instead of hard-coded value for clarity.


The documentation for this class was generated from the following file:
Generated on Mon Jul 10 19:45:29 2006 for Phoenix OSFS by  doxygen 1.4.2