14#ifndef ASYNCTASKCHAIN_H
15#define ASYNCTASKCHAIN_H
50class EXPCL_PANDA_EVENT AsyncTaskChain :
public TypedReferenceCount,
public Namable {
52 AsyncTaskChain(AsyncTaskManager *manager,
const std::string &name);
79 bool has_task(AsyncTask *task)
const;
91 virtual void output(std::ostream &out)
const;
92 virtual void write(std::ostream &out,
int indent_level = 0)
const;
95 class AsyncTaskChainThread;
96 typedef pvector< PT(AsyncTask) > TaskHeap;
98 void do_add(AsyncTask *task);
99 bool do_remove(AsyncTask *task,
bool upon_death=
false);
100 void do_wait_for_tasks();
103 bool do_has_task(AsyncTask *task)
const;
104 int find_task_on_heap(
const TaskHeap &heap, AsyncTask *task)
const;
106 void service_one_task(AsyncTaskChainThread *thread);
107 void cleanup_task(AsyncTask *task,
bool upon_death,
bool clean_exit);
108 bool finish_sort_group();
109 void filter_timeslice_priority();
110 void do_stop_threads();
111 void do_start_threads();
115 void cleanup_pickup_mode();
116 INLINE
double do_get_next_wake_time()
const;
117 static INLINE
double get_wake_time(AsyncTask *task);
118 void do_output(std::ostream &out)
const;
119 void do_write(std::ostream &out,
int indent_level)
const;
121 void write_task_line(std::ostream &out,
int indent_level, AsyncTask *task,
double now)
const;
124 class AsyncTaskChainThread :
public Thread {
126 AsyncTaskChainThread(
const std::string &name, AsyncTaskChain *chain);
127 virtual void thread_main();
129 AsyncTaskChain *_chain;
130 AsyncTask *_servicing;
133 class AsyncTaskSortWakeTime {
135 bool operator () (AsyncTask *a, AsyncTask *b)
const {
136 return AsyncTaskChain::get_wake_time(a) > AsyncTaskChain::get_wake_time(b);
140 class AsyncTaskSortPriority {
142 bool operator () (AsyncTask *a, AsyncTask *b)
const {
154 return a->_implicit_sort > b->_implicit_sort;
158 typedef pvector< PT(AsyncTaskChainThread) > Threads;
160 AsyncTaskManager *_manager;
172 bool _timeslice_priority;
174 ThreadPriority _thread_priority;
176 double _frame_budget;
178 int _num_busy_threads;
180 int _num_awaiting_tasks;
182 TaskHeap _this_active;
183 TaskHeap _next_active;
191 double _time_in_frame;
192 bool _block_till_next_frame;
194 unsigned int _next_implicit_sort;
203 static void init_type() {
204 TypedReferenceCount::init_type();
206 TypedReferenceCount::get_class_type());
209 return get_class_type();
211 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
216 friend class AsyncFuture;
217 friend class AsyncTaskChainThread;
218 friend class AsyncTask;
219 friend class AsyncTaskManager;
220 friend class AsyncTaskSortWakeTime;
223INLINE std::ostream &operator << (std::ostream &out,
const AsyncTaskChain &chain) {
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The AsyncTaskChain is a subset of the AsyncTaskManager.
bool has_task(AsyncTask *task) const
Returns true if the indicated task has been added to this AsyncTaskChain, false otherwise.
void set_tick_clock(bool tick_clock)
Sets the tick_clock flag.
bool is_started() const
Returns true if the thread(s) have been started and are ready to service requests,...
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 cal...
ThreadPriority get_thread_priority() const
Returns the priority associated with threads that serve this task chain.
int get_num_threads() const
Returns the number of threads that will be servicing tasks for this chain.
double get_frame_budget() const
Returns the maximum amount of time per frame the tasks on this chain are granted for execution.
bool get_tick_clock() const
Returns the tick_clock flag.
void wait_for_tasks()
Blocks until the task list is empty.
double get_next_wake_time() const
Returns the scheduled time (on the manager's clock) of the next sleeping task, on any task chain,...
void set_timeslice_priority(bool timeslice_priority)
Sets the timeslice_priority flag.
void set_num_threads(int num_threads)
Changes the number of threads for this task chain.
void stop_threads()
Stops any threads that are currently running.
void set_frame_budget(double frame_budget)
Sets the maximum amount of time per frame the tasks on this chain are granted for execution.
int get_num_tasks() const
Returns the number of tasks that are currently active or sleeping within the task chain.
void start_threads()
Starts any requested threads to service the tasks on the queue.
bool get_timeslice_priority() const
Returns the timeslice_priority flag.
void set_thread_priority(ThreadPriority priority)
Changes the priority associated with threads that serve this task chain.
AsyncTaskCollection get_tasks() const
Returns the set of tasks that are active or sleeping on the task chain, at the time of the call.
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 cal...
void poll()
Runs through all the tasks in the task list, once, if the task chain is running in single-threaded mo...
bool get_frame_sync() const
Returns the frame_sync flag.
void set_frame_sync(bool frame_sync)
Sets the frame_sync flag.
int get_num_running_threads() const
Returns the number of threads that have been created and are actively running.
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_priority
Returns the task's current priority value.
get_sort
Returns the task's current sort value.
double get_start_time() const
Returns the time at which the task was started, according to the task manager's clock.
This class implements a condition variable; see ConditionVar for a brief introduction to this class.
void output(std::ostream &out) const
Outputs the Namable.
A lightweight class that represents a single element that may be timed and/or counted via stats.
A thread; that is, a lightweight process.
TypeHandle is the identifier used to differentiate C++ class types.
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.