Panda3D
Classes | Public Member Functions | Static Public Member Functions | Friends | List of all members
AsyncTaskChain Class Reference

The AsyncTaskChain is a subset of the AsyncTaskManager. More...

#include "asyncTaskChain.h"

Inheritance diagram for AsyncTaskChain:
TypedReferenceCount Namable TypedObject ReferenceCount MemoryBase MemoryBase MemoryBase

Public Member Functions

 AsyncTaskChain (AsyncTaskManager *manager, const std::string &name)
 
virtual TypeHandle force_init_type ()
 
AsyncTaskCollection get_active_tasks () const
 Returns the set of tasks that are active (and not sleeping) on the task chain, at the time of the call. More...
 
double get_frame_budget () const
 Returns the maximum amount of time per frame the tasks on this chain are granted for execution. More...
 
bool get_frame_sync () const
 Returns the frame_sync flag. More...
 
double get_next_wake_time () const
 Returns the scheduled time (on the manager's clock) of the next sleeping task, on any task chain, to awaken. More...
 
int get_num_running_threads () const
 Returns the number of threads that have been created and are actively running. More...
 
int get_num_tasks () const
 Returns the number of tasks that are currently active or sleeping within the task chain. More...
 
int get_num_threads () const
 Returns the number of threads that will be servicing tasks for this chain. More...
 
AsyncTaskCollection get_sleeping_tasks () const
 Returns the set of tasks that are sleeping (and not active) on the task chain, at the time of the call. More...
 
AsyncTaskCollection get_tasks () const
 Returns the set of tasks that are active or sleeping on the task chain, at the time of the call. More...
 
ThreadPriority get_thread_priority () const
 Returns the priority associated with threads that serve this task chain. More...
 
bool get_tick_clock () const
 Returns the tick_clock flag. More...
 
bool get_timeslice_priority () const
 Returns the timeslice_priority flag. More...
 
virtual TypeHandle get_type () const
 
bool has_task (AsyncTask *task) const
 Returns true if the indicated task has been added to this AsyncTaskChain, false otherwise. More...
 
bool is_started () const
 Returns true if the thread(s) have been started and are ready to service requests, false otherwise. More...
 
virtual void output (std::ostream &out) const
 
void poll ()
 Runs through all the tasks in the task list, once, if the task chain is running in single-threaded mode (no threads available). More...
 
void set_frame_budget (double frame_budget)
 Sets the maximum amount of time per frame the tasks on this chain are granted for execution. More...
 
void set_frame_sync (bool frame_sync)
 Sets the frame_sync flag. More...
 
void set_num_threads (int num_threads)
 Changes the number of threads for this task chain. More...
 
void set_thread_priority (ThreadPriority priority)
 Changes the priority associated with threads that serve this task chain. More...
 
void set_tick_clock (bool tick_clock)
 Sets the tick_clock flag. More...
 
void set_timeslice_priority (bool timeslice_priority)
 Sets the timeslice_priority flag. More...
 
void start_threads ()
 Starts any requested threads to service the tasks on the queue. More...
 
void stop_threads ()
 Stops any threads that are currently running. More...
 
void wait_for_tasks ()
 Blocks until the task list is empty. More...
 
virtual void write (std::ostream &out, int indent_level=0) const
 
- 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)=default
 
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...
 
TypedObjectoperator= (const TypedObject &copy)=default
 
- Public Member Functions inherited from ReferenceCount
int get_ref_count () const
 
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 ref_if_nonzero () const
 Atomically increases the reference count of this object if it is not zero. 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...
 
WeakReferenceListweak_ref ()
 Adds the indicated PointerToVoid as a weak reference to this object. More...
 
void weak_unref ()
 Removes the indicated PointerToVoid as a weak reference to this object. More...
 
- Public Member Functions inherited from Namable
 Namable (const std::string &initial_name="")
 
void clear_name ()
 Resets the Namable's name to empty. More...
 
const std::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...
 
void output (std::ostream &out) const
 Outputs the Namable. More...
 
void set_name (const std::string &name)
 

Static Public Member Functions

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 AsyncFuture
 
class AsyncTask
 
class AsyncTaskChainThread
 
class AsyncTaskManager
 
class AsyncTaskSortWakeTime
 

Additional Inherited Members

- Public Attributes inherited from TypedObject
 get_type
 
- Public Attributes inherited from ReferenceCount
 get_ref_count
 Returns the current reference count. More...
 
- Public Attributes inherited from Namable
 get_name
 
 set_name
 

Detailed Description

The AsyncTaskChain is a subset of the AsyncTaskManager.

Each chain maintains a separate list of tasks, and will execute them with its own set of threads. Each chain may thereby operate independently of the other chains.

The AsyncTaskChain will spawn a specified number of threads (possibly 0) to serve the tasks. If there are no threads, you must call poll() from time to time to serve the tasks in the main thread. Normally this is done by calling AsyncTaskManager::poll().

Each task will run exactly once each epoch. Beyond that, the tasks' sort and priority values control the order in which they are run: tasks are run in increasing order by sort value, and within the same sort value, they are run roughly in decreasing order by priority value, with some exceptions for parallelism. Tasks with different sort values are never run in parallel together, but tasks with different priority values might be (if there is more than one thread).

Definition at line 50 of file asyncTaskChain.h.

Member Function Documentation

◆ get_active_tasks()

AsyncTaskCollection AsyncTaskChain::get_active_tasks ( ) const

Returns the set of tasks that are active (and not sleeping) on the task chain, at the time of the call.

Definition at line 345 of file asyncTaskChain.cxx.

◆ get_frame_budget()

double AsyncTaskChain::get_frame_budget ( ) const

Returns the maximum amount of time per frame the tasks on this chain are granted for execution.

See set_frame_budget().

Definition at line 192 of file asyncTaskChain.cxx.

◆ get_frame_sync()

bool AsyncTaskChain::get_frame_sync ( ) const

Returns the frame_sync flag.

See set_frame_sync().

Definition at line 221 of file asyncTaskChain.cxx.

◆ get_next_wake_time()

double AsyncTaskChain::get_next_wake_time ( ) const

Returns the scheduled time (on the manager's clock) of the next sleeping task, on any task chain, to awaken.

Returns -1 if there are no sleeping tasks.

Definition at line 380 of file asyncTaskChain.cxx.

◆ get_num_running_threads()

int AsyncTaskChain::get_num_running_threads ( ) const

Returns the number of threads that have been created and are actively running.

This will return 0 before the threads have been started; it will also return 0 if thread support is not available.

Definition at line 142 of file asyncTaskChain.cxx.

◆ get_num_tasks()

int AsyncTaskChain::get_num_tasks ( ) const

Returns the number of tasks that are currently active or sleeping within the task chain.

Definition at line 323 of file asyncTaskChain.cxx.

◆ get_num_threads()

int AsyncTaskChain::get_num_threads ( ) const

Returns the number of threads that will be servicing tasks for this chain.

Also see get_num_running_threads().

Definition at line 131 of file asyncTaskChain.cxx.

◆ get_sleeping_tasks()

AsyncTaskCollection AsyncTaskChain::get_sleeping_tasks ( ) const

Returns the set of tasks that are sleeping (and not active) on the task chain, at the time of the call.

Definition at line 355 of file asyncTaskChain.cxx.

◆ get_tasks()

AsyncTaskCollection AsyncTaskChain::get_tasks ( ) const

Returns the set of tasks that are active or sleeping on the task chain, at the time of the call.

Definition at line 333 of file asyncTaskChain.cxx.

References AsyncTaskCollection::add_tasks_from().

◆ get_thread_priority()

ThreadPriority AsyncTaskChain::get_thread_priority ( ) const

Returns the priority associated with threads that serve this task chain.

Definition at line 168 of file asyncTaskChain.cxx.

◆ get_tick_clock()

bool AsyncTaskChain::get_tick_clock ( ) const

Returns the tick_clock flag.

See set_tick_clock().

Definition at line 92 of file asyncTaskChain.cxx.

◆ get_timeslice_priority()

bool AsyncTaskChain::get_timeslice_priority ( ) const

Returns the timeslice_priority flag.

This changes the interpretation of priority, and the number of times per epoch each task will run. See set_timeslice_priority().

Definition at line 255 of file asyncTaskChain.cxx.

◆ has_task()

bool AsyncTaskChain::has_task ( AsyncTask task) const

Returns true if the indicated task has been added to this AsyncTaskChain, false otherwise.

Definition at line 292 of file asyncTaskChain.cxx.

◆ is_started()

bool AsyncTaskChain::is_started ( ) const
inline

Returns true if the thread(s) have been started and are ready to service requests, false otherwise.

If this is false, the next call to add() or add_and_do() will automatically start the threads.

Definition at line 20 of file asyncTaskChain.I.

◆ poll()

void AsyncTaskChain::poll ( )

Runs through all the tasks in the task list, once, if the task chain is running in single-threaded mode (no threads available).

This method does nothing in threaded mode, so it may safely be called in either case.

Normally, you would not call this function directly; instead, call AsyncTaskManager::poll(), which polls all of the task chains in sequence.

Definition at line 369 of file asyncTaskChain.cxx.

◆ set_frame_budget()

void AsyncTaskChain::set_frame_budget ( double  frame_budget)

Sets the maximum amount of time per frame the tasks on this chain are granted for execution.

If this is less than zero, there is no limit; if it is >= 0, it represents a maximum amount of time (in seconds) that will be used to execute tasks. If this time is exceeded in any one frame, the task chain will stop executing tasks until the next frame, as defined by the TaskManager's clock.

Definition at line 182 of file asyncTaskChain.cxx.

◆ set_frame_sync()

void AsyncTaskChain::set_frame_sync ( bool  frame_sync)

Sets the frame_sync flag.

When this flag is true, this task chain will be forced to sync with the TaskManager's clock. It will run no faster than one epoch per clock frame.

When this flag is false, the default, the task chain will finish all of its tasks and then immediately start from the first task again, regardless of the clock frame. When it is true, the task chain will finish all of its tasks and then wait for the clock to tick to the next frame before resuming the first task.

This only makes sense for threaded task chains. Non-threaded task chains are automatically synchronous.

Definition at line 212 of file asyncTaskChain.cxx.

◆ set_num_threads()

void AsyncTaskChain::set_num_threads ( int  num_threads)

Changes the number of threads for this task chain.

This may require stopping the threads if they are already running.

Definition at line 102 of file asyncTaskChain.cxx.

◆ set_thread_priority()

void AsyncTaskChain::set_thread_priority ( ThreadPriority  priority)

Changes the priority associated with threads that serve this task chain.

This may require stopping the threads if they are already running.

Definition at line 152 of file asyncTaskChain.cxx.

◆ set_tick_clock()

void AsyncTaskChain::set_tick_clock ( bool  tick_clock)

Sets the tick_clock flag.

When this is true, get_clock()->tick() will be called automatically at each task epoch. This is false by default.

Definition at line 83 of file asyncTaskChain.cxx.

◆ set_timeslice_priority()

void AsyncTaskChain::set_timeslice_priority ( bool  timeslice_priority)

Sets the timeslice_priority flag.

This changes the interpretation of priority, and the number of times per epoch each task will run.

When this flag is true, some tasks might not run in any given epoch. Instead, tasks with priority higher than 1 will be given precedence, in proportion to the amount of time they have already used. This gives higher-priority tasks more runtime than lower-priority tasks. Each task gets the amount of time proportional to its priority value, so a task with priority 100 will get five times as much processing time as a task with priority 20. For these purposes, priority values less than 1 are deemed to be equal to 1.

When this flag is false (the default), all tasks are run exactly once each epoch, round-robin style. Priority is only used to determine which task runs first within tasks of the same sort value.

Definition at line 244 of file asyncTaskChain.cxx.

◆ start_threads()

void AsyncTaskChain::start_threads ( )

Starts any requested threads to service the tasks on the queue.

This is normally not necessary, since adding a task will start the threads automatically.

Definition at line 280 of file asyncTaskChain.cxx.

◆ stop_threads()

void AsyncTaskChain::stop_threads ( )

Stops any threads that are currently running.

If any tasks are still pending and have not yet been picked up by a thread, they will not be serviced unless poll() or start_threads() is later called.

Definition at line 266 of file asyncTaskChain.cxx.

◆ wait_for_tasks()

void AsyncTaskChain::wait_for_tasks ( )

Blocks until the task list is empty.

Definition at line 313 of file asyncTaskChain.cxx.


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