# AsyncTaskChain

from pandac.PandaModules import AsyncTaskChain

Class : AsyncTaskChain
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).

## Inheritance:

AsyncTaskChain: TypedReferenceCount Namable
TypedReferenceCount: TypedObject ReferenceCount
TypedObject: MemoryBase
MemoryBase:
ReferenceCount: MemoryBase
Namable:

## Methods of AsyncTaskChain:

getActiveTasks
getClassType
getFrameBudget
getNextWakeTime
getNumRunningThreads
getNumTasks
getNumThreads
getSleepingTasks
getTasks
getThreadPriority
getTickClock
getTimeslicePriority
hasTask
isStarted
output
poll
setFrameBudget
setNumThreads
setThreadPriority
setTickClock
setTimeslicePriority
startThreads
stopThreads
waitForTasks
write

## Methods of TypedReferenceCount:

getClassType

## Methods of TypedObject:

getClassType
getType
getTypeIndex
isExactType
isOfType

## Methods of ReferenceCount:

getClassType
getRefCount
ref
testRefCountIntegrity
testRefCountNonzero
unref

## Methods of Namable:

Namable (Constructor)
clearName
getClassType
getName
hasName
operator =
output
setName

getActiveTasks AsyncTaskCollection AsyncTaskChain::get_active_tasks(void) const; Description: Returns the set of tasks that are active (and not sleeping) on the task chain, at the time of the call.

getClassType static TypeHandle AsyncTaskChain::get_class_type(void); Undocumented function.

getFrameBudget double AsyncTaskChain::get_frame_budget(void) const; Description: Returns the maximum amount of time per frame the tasks on this chain are granted for execution. See set_frame_budget().

getNextWakeTime double AsyncTaskChain::get_next_wake_time(void) const; Description: 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.

getNumRunningThreads int AsyncTaskChain::get_num_running_threads(void) const; Description: 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.

getNumTasks int AsyncTaskChain::get_num_tasks(void) const; Description: Returns the number of tasks that are currently active or sleeping within the task chain.

getNumThreads int AsyncTaskChain::get_num_threads(void) const; Description: Returns the number of threads that will be servicing tasks for this chain. Also see get_num_running_threads().

getSleepingTasks AsyncTaskCollection AsyncTaskChain::get_sleeping_tasks(void) const; Description: Returns the set of tasks that are sleeping (and not active) on the task chain, at the time of the call.

getTasks AsyncTaskCollection AsyncTaskChain::get_tasks(void) const; Description: Returns the set of tasks that are active or sleeping on the task chain, at the time of the call.

getThreadPriority ThreadPriority AsyncTaskChain::get_thread_priority(void) const; Description: Returns the priority associated with threads that serve this task chain.

getTickClock bool AsyncTaskChain::get_tick_clock(void) const; Description: Returns the tick_clock flag. See set_tick_clock().

getTimeslicePriority bool AsyncTaskChain::get_timeslice_priority(void) const; Description: 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().

hasTask bool AsyncTaskChain::has_task(AsyncTask *task) const; Description: Returns true if the indicated task has been added to this AsyncTaskChain, false otherwise.

isStarted bool AsyncTaskChain::is_started(void) const; Description: 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.

output virtual void AsyncTaskChain::output(ostream &out) const; Description:

poll void AsyncTaskChain::poll(void); Description: 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.

setFrameBudget void AsyncTaskChain::set_frame_budget(double frame_budget); Description: 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.

setNumThreads void AsyncTaskChain::set_num_threads(int num_threads); Description: Changes the number of threads for this task chain. This may require stopping the threads if they are already running.

setThreadPriority void AsyncTaskChain::set_thread_priority(ThreadPriority priority); Description: Changes the priority associated with threads that serve this task chain. This may require stopping the threads if they are already running.

setTickClock void AsyncTaskChain::set_tick_clock(bool tick_clock); Description: 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.

setTimeslicePriority void AsyncTaskChain::set_timeslice_priority(bool timeslice_priority); Description: 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.

startThreads void AsyncTaskChain::start_threads(void); Description: 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.

stopThreads void AsyncTaskChain::stop_threads(void); Description: 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.

waitForTasks void AsyncTaskChain::wait_for_tasks(void); Description: Blocks until the task list is empty.

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

getClassType static TypeHandle TypedReferenceCount::get_class_type(void); Undocumented function.

getClassType static TypeHandle TypedObject::get_class_type(void); Undocumented function.

getType virtual TypeHandle TypedObject::get_type(void) const = 0; Derived classes should override this function to return get_class_type().

getTypeIndex int TypedObject::get_type_index(void) const; Description: Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. This is equivalent to get_type().get_index().

isExactType bool TypedObject::is_exact_type(TypeHandle handle) const; Description: Returns true if the current object is the indicated type exactly.

isOfType bool TypedObject::is_of_type(TypeHandle handle) const; Description: Returns true if the current object is or derives from the indicated type.

getClassType static TypeHandle ReferenceCount::get_class_type(void); Undocumented function.

getRefCount int ReferenceCount::get_ref_count(void) const; Description: Returns the current reference count.

ref void ReferenceCount::ref(void) const; Description: Explicitly increments the reference count. User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically. This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it.

testRefCountIntegrity bool ReferenceCount::test_ref_count_integrity(void) const; Description: Does some easy checks to make sure that the reference count isn't completely bogus. Returns true if ok, false otherwise.

testRefCountNonzero bool ReferenceCount::test_ref_count_nonzero(void) const; Description: Does some easy checks to make sure that the reference count isn't zero, or completely bogus. Returns true if ok, false otherwise.

unref bool ReferenceCount::unref(void) const; Description: Explicitly decrements the reference count. Note that the object will not be implicitly deleted by unref() simply because the reference count drops to zero. (Having a member function delete itself is problematic; plus, we don't have a virtual destructor anyway.) However, see the helper function unref_delete(). User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically. This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it. The return value is true if the new reference count is nonzero, false if it is zero.

Namable Namable::Namable(string const &initial_name = ("")); Description:

clearName void Namable::clear_name(void); Description: Resets the Namable's name to empty.

getClassType static TypeHandle Namable::get_class_type(void); Undocumented function.

getName string const &Namable::get_name(void) const; Description:

hasName bool Namable::has_name(void) const; Description: Returns true if the Namable has a nonempty name set, false if the name is empty.

operator = Namable &Namable::operator =(Namable const &other); Description:

output void Namable::output(ostream &out) const; In the absence of any definition to the contrary, outputting a Namable will write out its name. Description: Outputs the Namable. This function simply writes the name to the output stream; most Namable derivatives will probably redefine this.

setName void Namable::set_name(string const &name); Description: