Panda3D
|
A class to manage a loose queue of isolated tasks, which can be performed either synchronously (in the foreground thread) or asynchronously (by a background thread). More...
Public Member Functions | |
AsyncTaskManager (string name) | |
add (AsyncTask task) | |
Adds the indicated task to the active queue. | |
cleanup () | |
Stops all threads and messily empties the task list. | |
clearName () | |
Resets the Namable's name to empty. | |
AsyncTask | findTask (string name) |
Returns the first task found with the indicated name, or NULL if there is no task with the indicated name. | |
AsyncTaskChain | findTaskChain (string name) |
Searches a new AsyncTaskChain of the indicated name and returns it if it exists, or NULL otherwise. | |
AsyncTaskCollection | findTasks (string name) |
Returns the list of tasks found with the indicated name. | |
AsyncTaskCollection | findTasksMatching (GlobPattern const pattern) |
Returns the list of tasks found whose name matches the indicated glob pattern, e.g. | |
AsyncTaskCollection | getActiveTasks () |
Returns the set of tasks that are active (and not sleeping) on the task manager, at the time of the call. | |
ClockObject | getClock () |
Returns the clock pointer used within the AsyncTaskManager. | |
string | getName () |
double | getNextWakeTime () |
Returns the scheduled time (on the manager's clock) of the next sleeping task, on any task chain, to awaken. | |
int | getNumTaskChains () |
Returns the number of different task chains. | |
int | getNumTasks () |
Returns the number of tasks that are currently active or sleeping within the task manager. | |
int | getRefCount () |
Returns the current reference count. | |
AsyncTaskCollection | getSleepingTasks () |
Returns the set of tasks that are sleeping (and not active) on the task manager, at the time of the call. | |
AsyncTaskChain | getTaskChain (int n) |
Returns the nth task chain. | |
list | getTaskChains () |
AsyncTaskCollection | getTasks () |
Returns the set of tasks that are active or sleeping on the task manager, at the time of the call. | |
TypeHandle | getType () |
int | getTypeIndex () |
Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. | |
bool | hasName () |
Returns true if the Namable has a nonempty name set, false if the name is empty. | |
bool | hasTask (AsyncTask task) |
Returns true if the indicated task has been added to this AsyncTaskManager, false otherwise. | |
bool | isExactType (TypeHandle handle) |
Returns true if the current object is the indicated type exactly. | |
bool | isOfType (TypeHandle handle) |
Returns true if the current object is or derives from the indicated type. | |
AsyncTaskChain | makeTaskChain (string name) |
Creates a new AsyncTaskChain of the indicated name and stores it within the AsyncTaskManager. | |
output (ostream out) | |
Outputs the Namable. | |
poll () | |
Runs through all the tasks in the task list, once, if the task manager is running in single-threaded mode (no threads available). | |
ref () | |
Explicitly increments the reference count. | |
bool | remove (AsyncTask task) |
Removes the indicated task from the active queue. | |
int | remove (AsyncTaskCollection const tasks) |
Removes all of the tasks in the AsyncTaskCollection. | |
bool | removeTaskChain (string name) |
Removes the AsyncTaskChain of the indicated name. | |
setClock (ClockObject clock) | |
Replaces the clock pointer used within the AsyncTaskManager. | |
setName (string name) | |
startThreads () | |
Starts any requested threads to service the tasks on the queue. | |
stopThreads () | |
Stops any threads that are currently running. | |
bool | testRefCountIntegrity () |
Does some easy checks to make sure that the reference count isn't completely bogus. | |
bool | testRefCountNonzero () |
Does some easy checks to make sure that the reference count isn't zero, or completely bogus. | |
bool | unref () |
Explicitly decrements the reference count. | |
waitForTasks () | |
Blocks until the task list is empty. | |
write (ostream out, int indent_level) | |
write (ostream out) | |
Static Public Member Functions | |
static TypeHandle | getClassType () |
static AsyncTaskManager | getGlobalPtr () |
Returns a pointer to the global AsyncTaskManager. |
A class to manage a loose queue of isolated tasks, which can be performed either synchronously (in the foreground thread) or asynchronously (by a background thread).
The AsyncTaskManager is actually a collection of AsyncTaskChains, each of which maintains a list of tasks. Each chain can be either foreground or background (it may run only in the main thread, or it may be serviced by one or more background threads). See AsyncTaskChain for more information.
If you do not require background processing, it is perfectly acceptable to create only one AsyncTaskChain, which runs in the main thread. This is a common configuration.
AsyncTaskManager | ( | string | name | ) |
add | ( | AsyncTask | task | ) |
Adds the indicated task to the active queue.
It is an error if the task is already added to this or any other active queue.
cleanup | ( | ) |
Stops all threads and messily empties the task list.
This is intended to be called on destruction only.
clearName | ( | ) | [inherited] |
Resets the Namable's name to empty.
Reimplemented in AsyncTask.
AsyncTask findTask | ( | string | name | ) |
Returns the first task found with the indicated name, or NULL if there is no task with the indicated name.
If there are multiple tasks with the same name, returns one of them arbitrarily.
AsyncTaskChain findTaskChain | ( | string | name | ) |
Searches a new AsyncTaskChain of the indicated name and returns it if it exists, or NULL otherwise.
AsyncTaskCollection findTasks | ( | string | name | ) |
Returns the list of tasks found with the indicated name.
AsyncTaskCollection findTasksMatching | ( | GlobPattern const | pattern | ) |
Returns the list of tasks found whose name matches the indicated glob pattern, e.g.
"my_task_*".
AsyncTaskCollection getActiveTasks | ( | ) |
Returns the set of tasks that are active (and not sleeping) on the task manager, at the time of the call.
static TypeHandle getClassType | ( | ) | [static] |
Reimplemented from TypedReferenceCount.
ClockObject getClock | ( | ) |
Returns the clock pointer used within the AsyncTaskManager.
See set_clock().
static AsyncTaskManager getGlobalPtr | ( | ) | [static] |
Returns a pointer to the global AsyncTaskManager.
This is the AsyncTaskManager that most code should use for queueing tasks and suchlike.
string getName | ( | ) | [inherited] |
Reimplemented in DynamicTextFont.
double getNextWakeTime | ( | ) |
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.
int getNumTaskChains | ( | ) |
Returns the number of different task chains.
int getNumTasks | ( | ) |
Returns the number of tasks that are currently active or sleeping within the task manager.
int getRefCount | ( | ) | [inherited] |
Returns the current reference count.
AsyncTaskCollection getSleepingTasks | ( | ) |
Returns the set of tasks that are sleeping (and not active) on the task manager, at the time of the call.
AsyncTaskChain getTaskChain | ( | int | n | ) |
Returns the nth task chain.
list getTaskChains | ( | ) |
AsyncTaskCollection getTasks | ( | ) |
Returns the set of tasks that are active or sleeping on the task manager, at the time of the call.
TypeHandle getType | ( | ) | [inherited] |
Reimplemented in AnimChannelBase.
int getTypeIndex | ( | ) | [inherited] |
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().
bool hasName | ( | ) | [inherited] |
Returns true if the Namable has a nonempty name set, false if the name is empty.
bool hasTask | ( | AsyncTask | task | ) |
Returns true if the indicated task has been added to this AsyncTaskManager, false otherwise.
bool isExactType | ( | TypeHandle | handle | ) | [inherited] |
Returns true if the current object is the indicated type exactly.
bool isOfType | ( | TypeHandle | handle | ) | [inherited] |
Returns true if the current object is or derives from the indicated type.
AsyncTaskChain makeTaskChain | ( | string | name | ) |
Creates a new AsyncTaskChain of the indicated name and stores it within the AsyncTaskManager.
If a task chain with this name already exists, returns it instead.
output | ( | ostream | out | ) |
poll | ( | ) |
Runs through all the tasks in the task list, once, if the task manager 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.
ref | ( | ) | [inherited] |
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.
int remove | ( | AsyncTaskCollection const | tasks | ) |
Removes all of the tasks in the AsyncTaskCollection.
Returns the number of tasks removed.
bool remove | ( | AsyncTask | task | ) |
Removes the indicated task from the active queue.
Returns true if the task is successfully removed, or false if it wasn't there.
bool removeTaskChain | ( | string | name | ) |
Removes the AsyncTaskChain of the indicated name.
If the chain still has tasks, this will block until all tasks are finished.
Returns true if successful, or false if the chain did not exist.
setClock | ( | ClockObject | clock | ) |
Replaces the clock pointer used within the AsyncTaskManager.
This is used to control when tasks with a set_delay() specified will be scheduled. It can also be ticked automatically each epoch, if set_tick_clock() is true.
The default is the global clock pointer.
startThreads | ( | ) |
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 | ( | ) |
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.
bool testRefCountIntegrity | ( | ) | [inherited] |
Does some easy checks to make sure that the reference count isn't completely bogus.
Returns true if ok, false otherwise.
Reimplemented in NodeReferenceCount, CachedTypedWritableReferenceCount, and NodeCachedReferenceCount.
bool testRefCountNonzero | ( | ) | [inherited] |
Does some easy checks to make sure that the reference count isn't zero, or completely bogus.
Returns true if ok, false otherwise.
bool unref | ( | ) | [inherited] |
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.) 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.
Reimplemented in GeomVertexArrayFormat, and GeomVertexFormat.
waitForTasks | ( | ) |
Blocks until the task list is empty.
write | ( | ostream | out | ) |