Panda3D

asyncTaskManager.I

00001 // Filename: asyncTaskManager.I
00002 // Created by:  drose (23Aug06)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: AsyncTaskManager::set_clock
00018 //       Access: Published
00019 //  Description: Replaces the clock pointer used within the
00020 //               AsyncTaskManager.  This is used to control when tasks
00021 //               with a set_delay() specified will be scheduled.  It
00022 //               can also be ticked automatically each epoch, if
00023 //               set_tick_clock() is true.
00024 //
00025 //               The default is the global clock pointer.
00026 ////////////////////////////////////////////////////////////////////
00027 INLINE void AsyncTaskManager::
00028 set_clock(ClockObject *clock) {
00029   _clock = clock;
00030 }
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 //     Function: AsyncTaskManager::get_clock
00034 //       Access: Published
00035 //  Description: Returns the clock pointer used within the
00036 //               AsyncTaskManager.  See set_clock().
00037 ////////////////////////////////////////////////////////////////////
00038 INLINE ClockObject *AsyncTaskManager::
00039 get_clock() {
00040   return _clock;
00041 }
00042 
00043 ////////////////////////////////////////////////////////////////////
00044 //     Function: AsyncTaskManager::get_num_tasks
00045 //       Access: Published
00046 //  Description: Returns the number of tasks that are currently active
00047 //               or sleeping within the task manager.
00048 ////////////////////////////////////////////////////////////////////
00049 INLINE int AsyncTaskManager::
00050 get_num_tasks() const {
00051   MutexHolder holder(_lock);
00052   return _num_tasks;
00053 }
00054 
00055 ////////////////////////////////////////////////////////////////////
00056 //     Function: AsyncTaskManager::get_global_ptr
00057 //       Access: Published
00058 //  Description: Returns a pointer to the global AsyncTaskManager.
00059 //               This is the AsyncTaskManager that most code should
00060 //               use for queueing tasks and suchlike.
00061 ////////////////////////////////////////////////////////////////////
00062 INLINE AsyncTaskManager *AsyncTaskManager::
00063 get_global_ptr() {
00064   if (_global_ptr == (AsyncTaskManager *)NULL) {
00065     make_global_ptr();
00066   }
00067   return _global_ptr;
00068 }
00069 
00070 ////////////////////////////////////////////////////////////////////
00071 //     Function: AsyncTaskManager::add_task_by_name
00072 //       Access: Protected
00073 //  Description: Adds the task to the _tasks_by_name index, if it has
00074 //               a nonempty name.
00075 ////////////////////////////////////////////////////////////////////
00076 INLINE void AsyncTaskManager::
00077 add_task_by_name(AsyncTask *task) {
00078   if (!task->get_name().empty()) {
00079     _tasks_by_name.insert(task);
00080   }
00081 }
 All Classes Functions Variables Enumerations