Panda3D

Loading...
Searching...
No Matches
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:

## 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.
double | get_frame_budget () const
| Returns the maximum amount of time per frame the tasks on this chain are granted for execution.
bool | get_frame_sync () const
| Returns the frame_sync flag.
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.
int | get_num_running_threads () const
| Returns the number of threads that have been created and are actively running.
int | get_num_tasks () const
| Returns the number of tasks that are currently active or sleeping within the task chain.
int | get_num_threads () const
| Returns the number of threads that will be servicing tasks for this chain.
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.
AsyncTaskCollection | get_tasks () const
| Returns the set of tasks that are active or sleeping on the task chain, at the time of the call.
ThreadPriority | get_thread_priority () const
| Returns the priority associated with threads that serve this task chain.
bool | get_tick_clock () const
| Returns the tick_clock flag.
bool | get_timeslice_priority () const
| Returns the timeslice_priority flag.
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.
bool | is_started () const
| Returns true if the thread(s) have been started and are ready to service requests, false otherwise.
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).
void | set_frame_budget (double frame_budget)
| Sets the maximum amount of time per frame the tasks on this chain are granted for execution.
void | set_frame_sync (bool frame_sync)
| Sets the frame_sync flag.
void | set_num_threads (int num_threads)
| Changes the number of threads for this task chain.
void | set_thread_priority (ThreadPriority priority)
| Changes the priority associated with threads that serve this task chain.
void | set_tick_clock (bool tick_clock)
| Sets the tick_clock flag.
void | set_timeslice_priority (bool timeslice_priority)
| Sets the timeslice_priority flag.
void | start_threads ()
| Starts any requested threads to service the tasks on the queue.
void | stop_threads ()
| Stops any threads that are currently running.
void | wait_for_tasks ()
| Blocks until the task list is empty.
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
TypedObject * | as_typed_object ()
| Returns the object, upcast (if necessary) to a TypedObject pointer.
const TypedObject * | as_typed_object () const
| Returns the object, upcast (if necessary) to a TypedObject pointer.
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.
bool | is_exact_type (TypeHandle handle) const
| Returns true if the current object is the indicated type exactly.
bool | is_of_type (TypeHandle handle) const
| Returns true if the current object is or derives from the indicated type.
TypedObject & | operator= (const TypedObject &copy)=default
Public Member Functions inherited from MemoryBase
void | operator delete (void *, void *)
void | operator delete (void *ptr)
void | operator delete[] (void *, void *)
void | operator delete[] (void *ptr)
void * | operator new (size_t size)
void * | operator new (size_t size, void *ptr)
void * | operator new[] (size_t size)
void * | operator new[] (size_t size, void *ptr)
Public Member Functions inherited from ReferenceCount
int | get_ref_count () const
WeakReferenceList * | get_weak_list () const
| Returns the WeakReferenceList associated with this ReferenceCount object.
bool | has_weak_list () const
| Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise.
void | local_object ()
| This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack.
void | ref () const
| Explicitly increments the reference count.
bool | ref_if_nonzero () const
| Atomically increases the reference count of this object if it is not zero.
bool | test_ref_count_integrity () const
| Does some easy checks to make sure that the reference count isn't completely bogus.
bool | test_ref_count_nonzero () const
| Does some easy checks to make sure that the reference count isn't zero, or completely bogus.
virtual bool | unref () const
| Explicitly decrements the reference count.
bool | unref_if_one () const
| Atomically decreases the reference count of this object if it is one.
WeakReferenceList * | weak_ref ()
| Adds the indicated PointerToVoid as a weak reference to this object.
void | weak_unref ()
| Removes the indicated PointerToVoid as a weak reference to this object.
Public Member Functions inherited from Namable
| Namable (const std::string &initial_name="")
void | clear_name ()
| Resets the Namable's name to empty.
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.
void | output (std::ostream &out) const
| Outputs the Namable.
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.
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.
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.

## Constructor & Destructor Documentation

## ◆ AsyncTaskChain()

AsyncTaskChain::AsyncTaskChain | ( | AsyncTaskManager * | manager,
|  | const std::string & | name )

Definition at line 39 of file asyncTaskChain.cxx.

## ◆ ~AsyncTaskChain()

AsyncTaskChain::~AsyncTaskChain | ( |  | ) |

Definition at line 67 of file asyncTaskChain.cxx.

## Member Function Documentation

## ◆ force_init_type()

virtual TypeHandle AsyncTaskChain::force_init_type | ( |  | ) |
| inline virtual

Reimplemented from TypedReferenceCount.

Definition at line 211 of file asyncTaskChain.h.

## ◆ 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 344 of file asyncTaskChain.cxx.

## ◆ get_class_type()

static TypeHandle AsyncTaskChain::get_class_type | ( |  | ) |
| inline static

Definition at line 200 of file asyncTaskChain.h.

## ◆ 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 191 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 220 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 379 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 141 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 322 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 130 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 354 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 332 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 167 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 91 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 254 of file asyncTaskChain.cxx.

## ◆ get_type()

virtual TypeHandle AsyncTaskChain::get_type | ( |  | ) | const
| inline virtual

Reimplemented from TypedReferenceCount.

Definition at line 208 of file asyncTaskChain.h.

## ◆ 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 291 of file asyncTaskChain.cxx.

## ◆ init_type()

static void AsyncTaskChain::init_type | ( |  | ) |
| inline static

Definition at line 203 of file asyncTaskChain.h.

## ◆ 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 19 of file asyncTaskChain.I.

## ◆ output()

void AsyncTaskChain::output | ( | std::ostream & | out | ) | const
| virtual

Definition at line 388 of file asyncTaskChain.cxx.

## ◆ 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 368 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 181 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 211 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 101 of file asyncTaskChain.cxx.

References Thread::is_threading_supported.

## ◆ 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 151 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 82 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 243 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 279 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 265 of file asyncTaskChain.cxx.

## ◆ wait_for_tasks()

void AsyncTaskChain::wait_for_tasks | ( |  | ) |

Blocks until the task list is empty.

Definition at line 312 of file asyncTaskChain.cxx.

## ◆ write()

void AsyncTaskChain::write | ( | std::ostream & | out,
|  | int | indent_level = 0 ) const
| virtual

Definition at line 397 of file asyncTaskChain.cxx.

## Friends And Related Symbol Documentation

## ◆ AsyncFuture

friend class AsyncFuture
| friend

Definition at line 216 of file asyncTaskChain.h.

## ◆ AsyncTask

friend class AsyncTask
| friend

Definition at line 218 of file asyncTaskChain.h.

## ◆ AsyncTaskChainThread

friend class AsyncTaskChainThread
| friend

Definition at line 217 of file asyncTaskChain.h.

## ◆ AsyncTaskManager

friend class AsyncTaskManager
| friend

Definition at line 219 of file asyncTaskChain.h.

## ◆ AsyncTaskSortWakeTime

friend class AsyncTaskSortWakeTime
| friend

Definition at line 220 of file asyncTaskChain.h.

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

- panda/src/event/asyncTaskChain.h
- panda/src/event/asyncTaskChain.cxx
- panda/src/event/asyncTaskChain.I