|
|
|
The AsyncTaskChain is a subset of the AsyncTaskManager.
More...
#include "asyncTaskChain.h"
List of all members.
Classes |
| class | AsyncTaskChainThread |
| class | AsyncTaskSortPriority |
| class | AsyncTaskSortWakeTime |
Public Member Functions |
|
| AsyncTaskChain (AsyncTaskManager *manager, const string &name) |
|
virtual TypeHandle | force_init_type () |
| 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 call.
|
| double | get_frame_budget () const |
| | Returns the maximum amount of time per frame the tasks on this chain are granted for execution.
|
| bool | get_frame_sync () const |
| | Returns the frame_sync flag.
|
| double | get_next_wake_time () const |
| | Returns the scheduled time (on the manager's clock) of the next sleeping task, on any task chain, to awaken.
|
| int | get_num_running_threads () const |
| | Returns the number of threads that have been created and are actively running.
|
| int | get_num_tasks () const |
| | Returns the number of tasks that are currently active or sleeping within the task chain.
|
| int | get_num_threads () const |
| | Returns the number of threads that will be servicing tasks for this chain.
|
| 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 call.
|
| AsyncTaskCollection | get_tasks () const |
| | Returns the set of tasks that are active or sleeping on the task chain, at the time of the call.
|
| ThreadPriority | get_thread_priority () const |
| | Returns the priority associated with threads that serve this task chain.
|
| bool | get_tick_clock () const |
| | Returns the tick_clock flag.
|
| bool | get_timeslice_priority () const |
| | Returns the timeslice_priority flag.
|
|
virtual TypeHandle | get_type () const |
| bool | has_task (AsyncTask *task) const |
| | Returns true if the indicated task has been added to this AsyncTaskChain, false otherwise.
|
| bool | is_started () const |
| | Returns true if the thread(s) have been started and are ready to service requests, false otherwise.
|
| virtual void | output (ostream &out) const |
| | Outputs the Namable.
|
| void | poll () |
| | Runs through all the tasks in the task list, once, if the task chain is running in single-threaded mode (no threads available).
|
| void | set_frame_budget (double frame_budget) |
| | Sets the maximum amount of time per frame the tasks on this chain are granted for execution.
|
| void | set_frame_sync (bool frame_sync) |
| | Sets the frame_sync flag.
|
| void | set_num_threads (int num_threads) |
| | Changes the number of threads for this task chain.
|
| void | set_thread_priority (ThreadPriority priority) |
| | Changes the priority associated with threads that serve this task chain.
|
| void | set_tick_clock (bool tick_clock) |
| | Sets the tick_clock flag.
|
| void | set_timeslice_priority (bool timeslice_priority) |
| | Sets the timeslice_priority flag.
|
| void | start_threads () |
| | Starts any requested threads to service the tasks on the queue.
|
| void | stop_threads () |
| | Stops any threads that are currently running.
|
| void | wait_for_tasks () |
| | Blocks until the task list is empty.
|
|
virtual void | write (ostream &out, int indent_level=0) const |
Static Public Member Functions |
|
static TypeHandle | get_class_type () |
|
static void | init_type () |
Protected Types |
| enum | State { S_initial,
S_started,
S_interrupted,
S_shutdown
} |
|
typedef pvector< PT(AsyncTask) > | TaskHeap |
|
typedef pvector< PT(AsyncTaskChainThread) > | Threads |
Protected Member Functions |
| void | cleanup_pickup_mode () |
| | Clean up the damage from setting pickup mode.
|
| void | cleanup_task (AsyncTask *task, bool upon_death, bool clean_exit) |
| | Called internally when a task has completed (or been interrupted) and is about to be removed from the active queue.
|
| void | do_add (AsyncTask *task) |
| | Adds the indicated task to the active queue.
|
| void | do_cleanup () |
| | Stops all threads and messily empties the task list.
|
| AsyncTaskCollection | do_get_active_tasks () const |
| | Returns the set of tasks that are active (and not sleeping) on the task chain, at the time of the call.
|
| double | do_get_next_wake_time () const |
| | Returns the time at which the next sleeping thread will awaken, or -1 if there are no sleeping threads.
|
| AsyncTaskCollection | do_get_sleeping_tasks () const |
| | Returns the set of tasks that are sleeping (and not active) on the task chain, at the time of the call.
|
| bool | do_has_task (AsyncTask *task) const |
| | Returns true if the task is on one of the task lists, false if it is not (false may mean that the task is currently being serviced).
|
| void | do_output (ostream &out) const |
| | The private implementation of output(), this assumes the lock is already held.
|
| void | do_poll () |
| | The private implementation of poll(), this assumes the lock is already held.
|
| bool | do_remove (AsyncTask *task) |
| | Removes the indicated task from this chain.
|
| void | do_start_threads () |
| | The private implementation of start_threads; assumes the lock is already held.
|
| void | do_stop_threads () |
| | The private implementation of stop_threads; assumes the lock is already held.
|
| void | do_wait_for_tasks () |
| | Blocks until the task list is empty.
|
| void | do_write (ostream &out, int indent_level) const |
| | The private implementation of write(), this assumes the lock is already held.
|
| void | filter_timeslice_priority () |
| | Called to filter the _active tasks list when we are in the special timeslice_priority mode.
|
| int | find_task_on_heap (const TaskHeap &heap, AsyncTask *task) const |
| | Returns the index number of the indicated task within the specified task list, or -1 if the task is not found in the list (this may mean that it is currently being serviced).
|
| bool | finish_sort_group () |
| | Called internally when all tasks of a given sort value have been completed, and it is time to increment to the next sort value, or begin the next epoch.
|
| void | service_one_task (AsyncTaskChainThread *thread) |
| | Pops a single task off the active queue, services it, and restores it to the end of the queue.
|
| void | write_task_line (ostream &out, int indent_level, AsyncTask *task, double now) const |
| | Writes a single line for a task in the report generated by do_write().
|
Static Protected Member Functions |
| static double | get_wake_time (AsyncTask *task) |
| | Returns the time at which the indicated thread will awaken.
|
Protected Attributes |
|
TaskHeap | _active |
|
bool | _block_till_next_frame |
|
int | _current_frame |
|
int | _current_sort |
|
ConditionVarFull | _cvar |
|
double | _frame_budget |
|
bool | _frame_sync |
|
AsyncTaskManager * | _manager |
|
bool | _needs_cleanup |
|
TaskHeap | _next_active |
|
int | _num_busy_threads |
|
int | _num_tasks |
|
int | _num_threads |
|
bool | _pickup_mode |
|
TaskHeap | _sleeping |
|
State | _state |
|
TaskHeap | _this_active |
|
ThreadPriority | _thread_priority |
|
Threads | _threads |
|
bool | _tick_clock |
|
double | _time_in_frame |
|
bool | _timeslice_priority |
Static Protected Attributes |
|
static PStatCollector | _task_pcollector |
|
static PStatCollector | _wait_pcollector |
Friends |
|
class | AsyncTask |
|
class | AsyncTaskChainThread |
|
class | AsyncTaskManager |
|
class | AsyncTaskSortWakeTime |
Detailed 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).
Definition at line 57 of file asyncTaskChain.h.
Member Function Documentation
The private implementation of stop_threads; assumes the lock is already held.
Definition at line 1119 of file asyncTaskChain.cxx.
References MutexDirect::acquire(), cleanup_pickup_mode(), Thread::get_current_thread(), Thread::join(), ConditionVarFullDirect::notify_all(), and MutexDirect::release().
Referenced by do_cleanup(), do_start_threads(), set_num_threads(), set_thread_priority(), stop_threads(), and AsyncTaskManager::stop_threads().
Called to filter the _active tasks list when we are in the special timeslice_priority mode.
In this mode, go through and postpone any tasks that have already exceeded their priority budget for this epoch.
Assumes the lock is already held.
Definition at line 1045 of file asyncTaskChain.cxx.
References AsyncTask::get_average_dt().
Referenced by finish_sort_group().
Returns the index number of the indicated task within the specified task list, or -1 if the task is not found in the list (this may mean that it is currently being serviced).
Assumes that the lock is currently held.
Definition at line 727 of file asyncTaskChain.cxx.
Referenced by do_has_task(), and do_remove().
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.
Definition at line 448 of file asyncTaskChain.cxx.
References do_get_next_wake_time().
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.
Definition at line 153 of file asyncTaskChain.cxx.
Returns the number of tasks that are currently active or sleeping within the task chain.
Definition at line 376 of file asyncTaskChain.cxx.
Returns the priority associated with threads that serve this task chain.
Definition at line 185 of file asyncTaskChain.cxx.
Returns the time at which the indicated thread will awaken.
Assumes the lock is already held.
Definition at line 51 of file asyncTaskChain.I.
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.
Definition at line 25 of file asyncTaskChain.I.
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.
Definition at line 435 of file asyncTaskChain.cxx.
References do_poll().
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.
Definition at line 203 of file asyncTaskChain.cxx.
Sets the frame_sync flag.
When this flag is true, this task chain will be forced to sync with the TaskManager's clock. It will run no faster than one epoch per clock frame.
When this flag is false, the default, the task chain will finish all of its tasks and then immediately start from the first task again, regardless of the clock frame. When it is true, the task chain will finish all of its tasks and then wait for the clock to tick to the next frame before resuming the first task.
This only makes sense for threaded task chains. Non-threaded task chains are automatically synchronous.
Definition at line 242 of file asyncTaskChain.cxx.
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.
Definition at line 83 of file asyncTaskChain.cxx.
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.
Definition at line 283 of file asyncTaskChain.cxx.
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.
Definition at line 327 of file asyncTaskChain.cxx.
References do_start_threads().
The documentation for this class was generated from the following files:
| | |