# AsyncTaskManager

from pandac.PandaModules import AsyncTaskManager

Class : AsyncTaskManager
Description : A class to manage a loose queue of isolated tasks, which can be performed by a background thread (in particular, for instance, loading a model file).
The AsyncTaskManager 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.
Each task, once added to the FIFO queue, will eventually be executed by one of the threads; if the task then indicates it has more work to do, it will be replaced at the end of the queue to go around again.

## Inheritance:

AsyncTaskManager: TypedReferenceCount Namable
TypedReferenceCount: TypedObject ReferenceCount
TypedObject: MemoryBase
MemoryBase:
ReferenceCount: MemoryBase
Namable:

## Methods of AsyncTaskManager:

add
addAndDo
getClassType
getNumTasks
getNumThreads
hasTask
isStarted
output
poll
remove
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:

clearName
getClassType
getName
hasName
operator =
output
setName

add void AsyncTaskManager::add(AsyncTask *task); Description: 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.

addAndDo bool AsyncTaskManager::add_and_do(AsyncTask *task); Description: Adds the indicated task to the active queue, and executes it immediately if this is a non-threaded task manager. The only difference between this method and add() is in the case of a non-threaded task manager: in this case, the method will execute the task inline, at least one frame, before returning. If the task completes in one frame, this means it will completely execute the task before returning in the non-threaded case. In the threaded case, this method behaves exactly the same as add(). The return value is true if the task has been added and is still pending, false if it has completed.

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

getNumTasks int AsyncTaskManager::get_num_tasks(void) const; Description: Returns the number of tasks that are currently active within the task manager.

getNumThreads int AsyncTaskManager::get_num_threads(void) const; Description: Returns the number of threads that have been created to service the tasks within this task manager. This will return 0 before the threads have been started; it will also return 0 if thread support is not available.

hasTask bool AsyncTaskManager::has_task(AsyncTask *task) const; Description: Returns true if the indicated task is currently in this manager's active queue, or false otherwise.

isStarted bool AsyncTaskManager::is_started(void) const; Filename: asyncTaskManager.I Created by: drose (23Aug06) PANDA 3D SOFTWARE Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved All use of this software is subject to the terms of the Panda 3d Software license. You should have received a copy of this license along with this source code; you will also find a current copy of the license at http://etc.cmu.edu/panda3d/docs/license/ . To contact the maintainers of this program write to panda3d-general@lists.sourceforge.net . 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 AsyncTaskManager::output(ostream &out) const; Description:

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

remove bool AsyncTaskManager::remove(AsyncTask *task); Description: Removes the indicated task from the active queue. Returns true if the task is successfully removed, or false if it wasn't there.

startThreads void AsyncTaskManager::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 AsyncTaskManager::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 AsyncTaskManager::wait_for_tasks(void); Description: Blocks until the task list is empty.

write virtual void AsyncTaskManager::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.

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: