Panda3D
asyncTaskManager.I
1 // Filename: asyncTaskManager.I
2 // Created by: drose (23Aug06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: AsyncTaskManager::set_clock
18 // Access: Published
19 // Description: Replaces the clock pointer used within the
20 // AsyncTaskManager. This is used to control when tasks
21 // with a set_delay() specified will be scheduled. It
22 // can also be ticked automatically each epoch, if
23 // set_tick_clock() is true.
24 //
25 // The default is the global clock pointer.
26 ////////////////////////////////////////////////////////////////////
27 INLINE void AsyncTaskManager::
29  _clock = clock;
30 }
31 
32 ////////////////////////////////////////////////////////////////////
33 // Function: AsyncTaskManager::get_clock
34 // Access: Published
35 // Description: Returns the clock pointer used within the
36 // AsyncTaskManager. See set_clock().
37 ////////////////////////////////////////////////////////////////////
40  return _clock;
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: AsyncTaskManager::get_num_tasks
45 // Access: Published
46 // Description: Returns the number of tasks that are currently active
47 // or sleeping within the task manager.
48 ////////////////////////////////////////////////////////////////////
49 INLINE int AsyncTaskManager::
50 get_num_tasks() const {
51  MutexHolder holder(_lock);
52  return _num_tasks;
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: AsyncTaskManager::get_global_ptr
57 // Access: Published
58 // Description: Returns a pointer to the global AsyncTaskManager.
59 // This is the AsyncTaskManager that most code should
60 // use for queueing tasks and suchlike.
61 ////////////////////////////////////////////////////////////////////
64  if (_global_ptr == (AsyncTaskManager *)NULL) {
65  make_global_ptr();
66  }
67  return _global_ptr;
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: AsyncTaskManager::add_task_by_name
72 // Access: Protected
73 // Description: Adds the task to the _tasks_by_name index, if it has
74 // a nonempty name.
75 ////////////////////////////////////////////////////////////////////
76 INLINE void AsyncTaskManager::
77 add_task_by_name(AsyncTask *task) {
78  if (!task->get_name().empty()) {
79  _tasks_by_name.insert(task);
80  }
81 }
A class to manage a loose queue of isolated tasks, which can be performed either synchronously (in th...
A lightweight C++ object whose constructor calls acquire() and whose destructor calls release() on a ...
Definition: mutexHolder.h:29
A ClockObject keeps track of elapsed real time and discrete time.
Definition: clockObject.h:66
int get_num_tasks() const
Returns the number of tasks that are currently active or sleeping within the task manager...
This class represents a concrete task performed by an AsyncManager.
Definition: asyncTask.h:43
ClockObject * get_clock()
Returns the clock pointer used within the AsyncTaskManager.
void set_clock(ClockObject *clock)
Replaces the clock pointer used within the AsyncTaskManager.
static AsyncTaskManager * get_global_ptr()
Returns a pointer to the global AsyncTaskManager.