00001 // Filename: conditionVarDirect.I 00002 // Created by: drose (13Feb06) 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: ConditionVarDirect::Constructor 00018 // Access: Public 00019 // Description: You must pass in a Mutex to the condition variable 00020 // constructor. This mutex may be shared by other 00021 // condition variables, if desired. It is the caller's 00022 // responsibility to ensure the Mutex object does not 00023 // destruct during the lifetime of the condition 00024 // variable. 00025 //////////////////////////////////////////////////////////////////// 00026 INLINE ConditionVarDirect:: 00027 ConditionVarDirect(MutexDirect &mutex) : 00028 _mutex(mutex), 00029 _impl(mutex._impl) 00030 { 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: ConditionVarDirect::Destructor 00035 // Access: Public 00036 // Description: 00037 //////////////////////////////////////////////////////////////////// 00038 INLINE ConditionVarDirect:: 00039 ~ConditionVarDirect() { 00040 } 00041 00042 //////////////////////////////////////////////////////////////////// 00043 // Function: ConditionVarDirect::Copy Constructor 00044 // Access: Private 00045 // Description: Do not attempt to copy condition variables. 00046 //////////////////////////////////////////////////////////////////// 00047 INLINE ConditionVarDirect:: 00048 ConditionVarDirect(const ConditionVarDirect ©) : 00049 _mutex(copy._mutex), 00050 _impl(_mutex._impl) 00051 { 00052 nassertv(false); 00053 } 00054 00055 //////////////////////////////////////////////////////////////////// 00056 // Function: ConditionVarDirect::Copy Assignment Operator 00057 // Access: Private 00058 // Description: Do not attempt to copy condition variables. 00059 //////////////////////////////////////////////////////////////////// 00060 INLINE void ConditionVarDirect:: 00061 operator = (const ConditionVarDirect ©) { 00062 nassertv(false); 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: ConditionVarDirect::get_mutex 00067 // Access: Public 00068 // Description: Returns the mutex associated with this condition 00069 // variable. 00070 //////////////////////////////////////////////////////////////////// 00071 INLINE MutexDirect &ConditionVarDirect:: 00072 get_mutex() const { 00073 return _mutex; 00074 } 00075 00076 //////////////////////////////////////////////////////////////////// 00077 // Function: ConditionVarDirect::wait 00078 // Access: Public 00079 // Description: Waits on the condition. The caller must already be 00080 // holding the lock associated with the condition 00081 // variable before calling this function. 00082 // 00083 // wait() will release the lock, then go to sleep until 00084 // some other thread calls notify() on this condition 00085 // variable. At that time at least one thread waiting 00086 // on the same ConditionVarDirect will grab the lock again, 00087 // and then return from wait(). 00088 // 00089 // It is possible that wait() will return even if no one 00090 // has called notify(). It is the responsibility of the 00091 // calling process to verify the condition on return 00092 // from wait, and possibly loop back to wait again if 00093 // necessary. 00094 // 00095 // Note the semantics of a condition variable: the mutex 00096 // must be held before wait() is called, and it will 00097 // still be held when wait() returns. However, it will 00098 // be temporarily released during the wait() call 00099 // itself. 00100 //////////////////////////////////////////////////////////////////// 00101 INLINE void ConditionVarDirect:: 00102 wait() { 00103 TAU_PROFILE("ConditionVarDirect::wait()", " ", TAU_USER); 00104 _impl.wait(); 00105 } 00106 00107 //////////////////////////////////////////////////////////////////// 00108 // Function: ConditionVarDirect::wait 00109 // Access: Published 00110 // Description: Waits on the condition, with a timeout. The function 00111 // will return when the condition variable is notified, 00112 // or the timeout occurs. There is no way to directly 00113 // tell which happened, and it is possible that neither 00114 // in fact happened (spurious wakeups are possible). 00115 // 00116 // See wait() with no parameters for more. 00117 //////////////////////////////////////////////////////////////////// 00118 void ConditionVarDirect:: 00119 wait(double timeout) { 00120 TAU_PROFILE("ConditionVarDirect::wait(double)", " ", TAU_USER); 00121 _impl.wait(timeout); 00122 } 00123 00124 //////////////////////////////////////////////////////////////////// 00125 // Function: ConditionVarDirect::notify 00126 // Access: Public 00127 // Description: Informs one of the other threads who are currently 00128 // blocked on wait() that the relevant condition has 00129 // changed. If multiple threads are currently waiting, 00130 // at least one of them will be woken up, although there 00131 // is no way to predict which one. It is possible that 00132 // more than one thread will be woken up. 00133 // 00134 // The caller must be holding the mutex associated with 00135 // the condition variable before making this call, which 00136 // will not release the mutex. 00137 // 00138 // If no threads are waiting, this is a no-op: the 00139 // notify event is lost. 00140 //////////////////////////////////////////////////////////////////// 00141 INLINE void ConditionVarDirect:: 00142 notify() { 00143 TAU_PROFILE("ConditionVarDirect::notify()", " ", TAU_USER); 00144 _impl.notify(); 00145 }