Panda3D
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
AsyncTask Class Reference

This class represents a concrete task performed by an AsyncManager. More...

#include "asyncTask.h"

Inheritance diagram for AsyncTask:
AsyncTaskBase TypedReferenceCount Namable TypedObject ReferenceCount MemoryBase MemoryBase MemoryBase AnimateVerticesRequest AsyncTaskPause AsyncTaskSequence AudioLoadRequest GenericAsyncTask ModelFlattenRequest ModelLoadRequest ModelSaveRequest TextureReloadRequest

Public Types

enum  DoneStatus {
  DS_done, DS_cont, DS_again, DS_pickup,
  DS_exit, DS_pause, DS_interrupt
}
 
enum  State {
  S_inactive, S_active, S_servicing, S_servicing_removed,
  S_sleeping, S_active_nested
}
 

Public Member Functions

 AsyncTask (const string &name=string())
 
void clear_delay ()
 Removes any delay specified for the task. More...
 
void clear_name ()
 Resets the task's name to empty. More...
 
virtual TypeHandle force_init_type ()
 
double get_average_dt () const
 Returns the average amount of time elapsed during each of the task's previous run cycles, in seconds. More...
 
double get_delay () const
 Returns the delay value that has been set via set_delay, if any. More...
 
const string & get_done_event () const
 Returns the event name that will be triggered when the task finishes. More...
 
double get_dt () const
 Returns the amount of time elapsed during the task's previous run cycle, in seconds. More...
 
int get_elapsed_frames () const
 Returns the number of frames that have elapsed since the task was started, according to the task manager's clock. More...
 
double get_elapsed_time () const
 Returns the amount of time that has elapsed since the task was started, according to the task manager's clock. More...
 
AsyncTaskManagerget_manager () const
 Returns the AsyncTaskManager that this task is active on. More...
 
double get_max_dt () const
 Returns the maximum amount of time elapsed during any one of the task's previous run cycles, in seconds. More...
 
string get_name_prefix () const
 Returns the initial part of the name, up to but not including any trailing digits following a hyphen or underscore. More...
 
int get_priority () const
 Returns the task's current priority value. More...
 
int get_sort () const
 Returns the task's current sort value. More...
 
int get_start_frame () const
 Returns the frame number at which the task was started, according to the task manager's clock. More...
 
double get_start_time () const
 Returns the time at which the task was started, according to the task manager's clock. More...
 
State get_state () const
 Returns the current state of the task. More...
 
const string & get_task_chain () const
 Returns the AsyncTaskChain on which this task will be running. More...
 
AtomicAdjust::Integer get_task_id () const
 Returns a number guaranteed to be unique for each different AsyncTask object in the universe. More...
 
virtual TypeHandle get_type () const
 
double get_wake_time () const
 If this task has been added to an AsyncTaskManager with a delay in effect, this returns the time at which the task is expected to awaken. More...
 
bool has_delay () const
 Returns true if a delay has been set for this task via set_delay(), or false otherwise. More...
 
bool is_alive () const
 Returns true if the task is currently active or sleeping on some task chain, meaning that it will be executed in its turn, or false if it is not active. More...
 
virtual void output (ostream &out) const
 
void recalc_wake_time ()
 If the task is currently sleeping on a task chain, this resets its wake time to the current time + get_delay(). More...
 
void remove ()
 Removes the task from its active manager, if any, and makes the state S_inactive (or possible S_servicing_removed). More...
 
void set_delay (double delay)
 Specifies the amount of time, in seconds, by which this task will be delayed after it has been added to the AsyncTaskManager. More...
 
void set_done_event (const string &done_event)
 Sets the event name that will be triggered when the task finishes. More...
 
void set_name (const string &name)
 
void set_priority (int priority)
 Specifies a priority value for this task. More...
 
void set_sort (int sort)
 Specifies a sort value for this task. More...
 
void set_task_chain (const string &chain_name)
 Specifies the AsyncTaskChain on which this task will be running. More...
 
- Public Member Functions inherited from TypedReferenceCount
 TypedReferenceCount (const TypedReferenceCount &copy)
 
void operator= (const TypedReferenceCount &copy)
 
- Public Member Functions inherited from TypedObject
 TypedObject (const TypedObject &copy)
 
TypedObjectas_typed_object ()
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
const TypedObjectas_typed_object () const
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
int get_best_parent_from_Set (const std::set< int > &) const
 
int get_type_index () const
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More...
 
bool is_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly. More...
 
bool is_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type. More...
 
void operator= (const TypedObject &copy)
 
- Public Member Functions inherited from ReferenceCount
int get_ref_count () const
 Returns the current reference count. More...
 
WeakReferenceListget_weak_list () const
 Returns the WeakReferenceList associated with this ReferenceCount object. More...
 
bool has_weak_list () const
 Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise. More...
 
void local_object ()
 This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack. More...
 
void ref () const
 Explicitly increments the reference count. More...
 
bool test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus. More...
 
bool test_ref_count_nonzero () const
 Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More...
 
virtual bool unref () const
 Explicitly decrements the reference count. More...
 
void weak_ref (WeakPointerToVoid *ptv)
 Adds the indicated PointerToVoid as a weak reference to this object. More...
 
void weak_unref (WeakPointerToVoid *ptv)
 Removes the indicated PointerToVoid as a weak reference to this object. More...
 
- Public Member Functions inherited from Namable
 Namable (const string &initial_name="")
 
 Namable (const Namable &copy)
 
void clear_name ()
 Resets the Namable's name to empty. More...
 
const string & get_name () const
 
bool has_name () const
 Returns true if the Namable has a nonempty name set, false if the name is empty. More...
 
Namableoperator= (const Namable &other)
 
void output (ostream &out) const
 Outputs the Namable. More...
 
void set_name (const string &name)
 

Static Public Member Functions

static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from AsyncTaskBase
static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from TypedReferenceCount
static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from TypedObject
static TypeHandle get_class_type ()
 
static void init_type ()
 This function is declared non-inline to work around a compiler bug in g++ 2.96. More...
 
- Static Public Member Functions inherited from ReferenceCount
static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from Namable
static TypeHandle get_class_type ()
 
static void init_type ()
 

Friends

class AsyncTaskChain
 
class AsyncTaskManager
 
class AsyncTaskSequence
 

Detailed Description

This class represents a concrete task performed by an AsyncManager.

Normally, you would subclass from this class, and override do_task(), to define the functionality you wish to have the task perform.

Definition at line 43 of file asyncTask.h.

Member Function Documentation

◆ clear_delay()

void AsyncTask::clear_delay ( )
inline

Removes any delay specified for the task.

The next time the task is added to the queue, it will run immediately. This does not affect the task's wake time if it has already been added to the queue.

Definition at line 100 of file asyncTask.I.

References has_delay().

Referenced by set_delay().

◆ clear_name()

void AsyncTask::clear_name ( )
inline

Resets the task's name to empty.

Definition at line 163 of file asyncTask.I.

References get_task_id().

Referenced by get_start_frame().

◆ get_average_dt()

double AsyncTask::get_average_dt ( ) const
inline

Returns the average amount of time elapsed during each of the task's previous run cycles, in seconds.

Definition at line 302 of file asyncTask.I.

Referenced by get_max_dt(), and AsyncTaskChain::get_next_wake_time().

◆ get_delay()

double AsyncTask::get_delay ( ) const
inline

Returns the delay value that has been set via set_delay, if any.

Definition at line 123 of file asyncTask.I.

References get_start_time().

Referenced by AsyncTaskChain::get_next_wake_time(), and has_delay().

◆ get_done_event()

const string & AsyncTask::get_done_event ( ) const
inline

Returns the event name that will be triggered when the task finishes.

See set_done_event().

Definition at line 235 of file asyncTask.I.

References get_dt().

Referenced by set_done_event().

◆ get_dt()

double AsyncTask::get_dt ( ) const
inline

Returns the amount of time elapsed during the task's previous run cycle, in seconds.

Definition at line 280 of file asyncTask.I.

References get_max_dt().

Referenced by get_done_event().

◆ get_elapsed_frames()

int AsyncTask::get_elapsed_frames ( ) const

Returns the number of frames that have elapsed since the task was started, according to the task manager's clock.

It is only valid to call this if the task's status is not S_inactive.

Definition at line 177 of file asyncTask.cxx.

References get_name_prefix().

Referenced by get_elapsed_time().

◆ get_elapsed_time()

double AsyncTask::get_elapsed_time ( ) const

Returns the amount of time that has elapsed since the task was started, according to the task manager's clock.

It is only valid to call this if the task's status is not S_inactive.

Definition at line 160 of file asyncTask.cxx.

References get_elapsed_frames().

Referenced by recalc_wake_time().

◆ get_manager()

AsyncTaskManager * AsyncTask::get_manager ( ) const
inline

Returns the AsyncTaskManager that this task is active on.

This will be NULL if the state is S_inactive.

Definition at line 61 of file asyncTask.I.

References set_delay().

Referenced by is_alive().

◆ get_max_dt()

double AsyncTask::get_max_dt ( ) const
inline

Returns the maximum amount of time elapsed during any one of the task's previous run cycles, in seconds.

Definition at line 291 of file asyncTask.I.

References get_average_dt().

Referenced by get_dt().

◆ get_name_prefix()

string AsyncTask::get_name_prefix ( ) const

Returns the initial part of the name, up to but not including any trailing digits following a hyphen or underscore.

Definition at line 249 of file asyncTask.cxx.

References GraphicsOutput::get_name(), and set_task_chain().

Referenced by get_elapsed_frames().

◆ get_priority()

int AsyncTask::get_priority ( ) const
inline

Returns the task's current priority value.

See set_priority().

Definition at line 209 of file asyncTask.I.

References set_done_event().

Referenced by GraphicsStateGuardian::create_gamma_table(), and get_sort().

◆ get_sort()

int AsyncTask::get_sort ( ) const
inline

Returns the task's current sort value.

See set_sort().

Definition at line 198 of file asyncTask.I.

References get_priority().

Referenced by AsyncTaskChain::get_next_wake_time(), and get_task_chain().

◆ get_start_frame()

int AsyncTask::get_start_frame ( ) const
inline

Returns the frame number at which the task was started, according to the task manager's clock.

It is only valid to call this if the task's status is not S_inactive.

Definition at line 152 of file asyncTask.I.

References clear_name().

Referenced by get_start_time().

◆ get_start_time()

double AsyncTask::get_start_time ( ) const
inline

Returns the time at which the task was started, according to the task manager's clock.

It is only valid to call this if the task's status is not S_inactive.

Definition at line 137 of file asyncTask.I.

References get_start_frame().

Referenced by get_delay().

◆ get_state()

AsyncTask::State AsyncTask::get_state ( ) const
inline

Returns the current state of the task.

Definition at line 22 of file asyncTask.I.

References is_alive().

◆ get_task_chain()

const string & AsyncTask::get_task_chain ( ) const
inline

Returns the AsyncTaskChain on which this task will be running.

Each task chain runs tasks independently of the others.

Definition at line 186 of file asyncTask.I.

References get_sort().

Referenced by get_task_id().

◆ get_task_id()

AtomicAdjust::Integer AsyncTask::get_task_id ( ) const
inline

Returns a number guaranteed to be unique for each different AsyncTask object in the universe.

Definition at line 174 of file asyncTask.I.

References get_task_chain().

Referenced by clear_name().

◆ get_wake_time()

double AsyncTask::get_wake_time ( ) const

If this task has been added to an AsyncTaskManager with a delay in effect, this returns the time at which the task is expected to awaken.

It has no meaning if the task has not yet been added to a queue, or if there was no delay in effect at the time the task was added.

If the task's status is not S_sleeping, this returns 0.0.

Definition at line 107 of file asyncTask.cxx.

References recalc_wake_time().

Referenced by remove().

◆ has_delay()

bool AsyncTask::has_delay ( ) const
inline

Returns true if a delay has been set for this task via set_delay(), or false otherwise.

Definition at line 112 of file asyncTask.I.

References get_delay().

Referenced by clear_delay(), and AsyncTaskChain::get_next_wake_time().

◆ is_alive()

bool AsyncTask::is_alive ( ) const
inline

Returns true if the task is currently active or sleeping on some task chain, meaning that it will be executed in its turn, or false if it is not active.

If the task has recently been removed while it is in the middle of execution, this will return false, because the task will not run again once it finishes.

Definition at line 37 of file asyncTask.I.

References get_manager().

Referenced by get_state().

◆ recalc_wake_time()

void AsyncTask::recalc_wake_time ( )

If the task is currently sleeping on a task chain, this resets its wake time to the current time + get_delay().

It is as if the task had suddenly returned DS_again. The task will sleep for its current delay seconds before running again. This method may therefore be used to make the task wake up sooner or later than it would have otherwise.

If the task is not already sleeping, this method has no effect.

Definition at line 135 of file asyncTask.cxx.

References get_elapsed_time().

Referenced by get_wake_time().

◆ remove()

void AsyncTask::remove ( )

Removes the task from its active manager, if any, and makes the state S_inactive (or possible S_servicing_removed).

This is a no-op if the state is already S_inactive.

Definition at line 87 of file asyncTask.cxx.

References get_wake_time().

◆ set_delay()

void AsyncTask::set_delay ( double  delay)
inline

Specifies the amount of time, in seconds, by which this task will be delayed after it has been added to the AsyncTaskManager.

At least the specified amount of time (and possibly more) will elapse before the task begins.

You may specify a delay of 0.0 to guarantee that the task will run in the next epoch following the one in which it is added.

Setting this value after the task has already been added will not affect the task's wake time; it will only affect the task if it is re-added to the queue in the future, for instance if the task returns DS_again. However, see recalc_wake_time() if you wish to apply the delay effect immediately.

Definition at line 86 of file asyncTask.I.

References clear_delay().

Referenced by get_manager().

◆ set_done_event()

void AsyncTask::set_done_event ( const string &  done_event)
inline

Sets the event name that will be triggered when the task finishes.

This should only be called before the task has been started, or after it has finished and before it is about to be restarted (i.e. when get_state() returns S_inactive).

Definition at line 223 of file asyncTask.I.

References get_done_event().

Referenced by get_priority().

◆ set_priority()

void AsyncTask::set_priority ( int  priority)

Specifies a priority value for this task.

In general, tasks with a higher priority value are executed before tasks with a lower priority value (but only for tasks with the same sort value).

Unlike the sort value, tasks with different priorities may execute at the same time, if the AsyncTaskManager has more than one thread servicing tasks.

Also see AsyncTaskChain::set_timeslice_priority(), which changes the meaning of this value. In the default mode, when the timeslice_priority flag is false, all tasks always run once per epoch, regardless of their priority values (that is, the priority controls the order of the task execution only, not the number of times it runs). On the other hand, if you set the timeslice_priority flag to true, then changing a task's priority has an effect on the number of times it runs.

Definition at line 376 of file asyncTask.cxx.

References Thread::get_current_thread(), and GraphicsOutput::get_name().

Referenced by GraphicsStateGuardian::create_gamma_table(), set_sort(), and PartBundle::write().

◆ set_sort()

void AsyncTask::set_sort ( int  sort)

Specifies a sort value for this task.

Within a given AsyncTaskManager, all of the tasks with a given sort value are guaranteed to be completed before any tasks with a higher sort value are begun.

To put it another way, two tasks might execute in parallel with each other only if they both have the same sort value. Tasks with a lower sort value are executed first.

This is different from the priority, which makes no such exclusion guarantees.

Definition at line 324 of file asyncTask.cxx.

References set_priority().

Referenced by set_task_chain().

◆ set_task_chain()

void AsyncTask::set_task_chain ( const string &  chain_name)

Specifies the AsyncTaskChain on which this task will be running.

Each task chain runs tasks independently of the others.

Definition at line 277 of file asyncTask.cxx.

References set_sort().

Referenced by get_name_prefix(), Loader::remove(), and Loader::save_async().


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