14#ifndef ASYNCTASKMANAGER_H
15#define ASYNCTASKMANAGER_H
48class EXPCL_PANDA_EVENT AsyncTaskManager :
public TypedReferenceCount,
public Namable {
50 explicit AsyncTaskManager(
const std::string &name);
51 BLOCKING
virtual ~AsyncTaskManager();
66 void add(AsyncTask *task);
67 bool has_task(AsyncTask *task)
const;
69 AsyncTask *
find_task(
const std::string &name)
const;
73 bool remove(AsyncTask *task);
93 virtual void output(std::ostream &out)
const;
94 virtual void write(std::ostream &out,
int indent_level = 0)
const;
99 AsyncTaskChain *do_make_task_chain(
const std::string &name);
100 AsyncTaskChain *do_find_task_chain(
const std::string &name);
102 INLINE
void add_task_by_name(AsyncTask *task);
103 void remove_task_by_name(AsyncTask *task);
105 bool do_has_task(AsyncTask *task)
const;
107 virtual void do_output(std::ostream &out)
const;
110 static void make_global_ptr();
113 class AsyncTaskSortName {
115 bool operator () (AsyncTask *a, AsyncTask *b)
const {
116 return a->get_name() < b->get_name();
120 typedef pmultiset<AsyncTask *, AsyncTaskSortName> TasksByName;
126 typedef ov_set<PT(AsyncTaskChain), IndirectCompareNames<AsyncTaskChain> > TaskChains;
127 TaskChains _task_chains;
130 TasksByName _tasks_by_name;
131 PT(ClockObject) _clock;
133 ConditionVarFull _frame_cvar;
135 static AsyncTaskManager* _global_ptr;
138 static TypeHandle get_class_type() {
141 static void init_type() {
142 TypedReferenceCount::init_type();
144 TypedReferenceCount::get_class_type());
146 virtual TypeHandle get_type()
const {
147 return get_class_type();
149 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
152 static TypeHandle _type_handle;
154 friend class AsyncFuture;
155 friend class AsyncTaskChain;
156 friend class AsyncTaskChain::AsyncTaskChainThread;
157 friend class AsyncTask;
158 friend class AsyncTaskSequence;
159 friend class PythonTask;
162INLINE std::ostream &operator << (std::ostream &out,
const AsyncTaskManager &manager) {
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A list of tasks, for instance as returned by some of the AsyncTaskManager query functions.
A class to manage a loose queue of isolated tasks, which can be performed either synchronously (in th...
get_num_task_chains
Returns the number of different task chains.
size_t get_num_tasks() const
Returns the number of tasks that are currently active or sleeping within the task manager.
void wait_for_tasks()
Blocks until the task list is empty.
bool remove(AsyncTask *task)
Removes the indicated task from the active queue.
void add(AsyncTask *task)
Adds the indicated task to the active queue.
AsyncTaskCollection find_tasks_matching(const GlobPattern &pattern) const
Returns the list of tasks found whose name matches the indicated glob pattern, e.g.
get_clock
Returns the clock pointer used within the AsyncTaskManager.
void stop_threads()
Stops any threads that are currently running.
void poll()
Runs through all the tasks in the task list, once, if the task manager is running in single-threaded ...
AsyncTaskChain * find_task_chain(const std::string &name)
Searches a new AsyncTaskChain of the indicated name and returns it if it exists, or NULL otherwise.
void cleanup()
Stops all threads and messily empties the task list.
get_sleeping_tasks
Returns the set of tasks that are sleeping (and not active) on the task manager, at the time of the c...
get_next_wake_time
Returns the scheduled time (on the manager's clock) of the next sleeping task, on any task chain,...
AsyncTaskChain * make_task_chain(const std::string &name)
Creates a new AsyncTaskChain of the indicated name and stores it within the AsyncTaskManager.
set_clock
Replaces the clock pointer used within the AsyncTaskManager.
get_tasks
Returns the set of tasks that are active or sleeping on the task manager, at the time of the call.
AsyncTask * find_task(const std::string &name) const
Returns the first task found with the indicated name, or NULL if there is no task with the indicated ...
get_active_tasks
Returns the set of tasks that are active (and not sleeping) on the task manager, at the time of the c...
get_task_chain
Returns the nth task chain.
bool has_task(AsyncTask *task) const
Returns true if the indicated task has been added to this AsyncTaskManager, false otherwise.
bool remove_task_chain(const std::string &name)
Removes the AsyncTaskChain of the indicated name.
void start_threads()
Starts any requested threads to service the tasks on the queue.
AsyncTaskCollection find_tasks(const std::string &name) const
Returns the list of tasks found with the indicated name.
static AsyncTaskManager * get_global_ptr()
Returns a pointer to the global AsyncTaskManager.
A ClockObject keeps track of elapsed real time and discrete time.
This class can be used to test for string matches against standard Unix- shell filename globbing conv...
void output(std::ostream &out) const
Outputs the Namable.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.