00001 // Filename: lightReMutexDirect.I 00002 // Created by: drose (08Oct08) 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: LightReMutexDirect::Constructor 00018 // Access: Protected 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE LightReMutexDirect:: 00022 LightReMutexDirect() 00023 #ifndef HAVE_REMUTEXIMPL 00024 : _cvar_impl(_lock_impl) 00025 #endif 00026 { 00027 #ifndef HAVE_REMUTEXIMPL 00028 _locking_thread = NULL; 00029 _lock_count = 0; 00030 #endif 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: LightReMutexDirect::Destructor 00035 // Access: Protected 00036 // Description: 00037 //////////////////////////////////////////////////////////////////// 00038 INLINE LightReMutexDirect:: 00039 ~LightReMutexDirect() { 00040 } 00041 00042 //////////////////////////////////////////////////////////////////// 00043 // Function: LightReMutexDirect::Copy Constructor 00044 // Access: Private 00045 // Description: Do not attempt to copy lightReMutexes. 00046 //////////////////////////////////////////////////////////////////// 00047 INLINE LightReMutexDirect:: 00048 LightReMutexDirect(const LightReMutexDirect ©) 00049 #ifndef HAVE_REMUTEXIMPL 00050 : _cvar_impl(_lock_impl) 00051 #endif 00052 { 00053 nassertv(false); 00054 } 00055 00056 //////////////////////////////////////////////////////////////////// 00057 // Function: LightReMutexDirect::Copy Assignment Operator 00058 // Access: Private 00059 // Description: Do not attempt to copy lightReMutexes. 00060 //////////////////////////////////////////////////////////////////// 00061 INLINE void LightReMutexDirect:: 00062 operator = (const LightReMutexDirect ©) { 00063 nassertv(false); 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: LightReMutexDirect::acquire 00068 // Access: Published 00069 // Description: Grabs the lightReMutex if it is available. If it is not 00070 // available, blocks until it becomes available, then 00071 // grabs it. In either case, the function does not 00072 // return until the lightReMutex is held; you should then call 00073 // unlock(). 00074 // 00075 // This method is considered const so that you can lock 00076 // and unlock const lightReMutexes, mainly to allow thread-safe 00077 // access to otherwise const data. 00078 // 00079 // Also see LightReMutexHolder. 00080 //////////////////////////////////////////////////////////////////// 00081 INLINE void LightReMutexDirect:: 00082 acquire() const { 00083 TAU_PROFILE("void LightReMutexDirect::acquire()", " ", TAU_USER); 00084 ((LightReMutexDirect *)this)->_impl.acquire(); 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: LightReMutexDirect::acquire 00089 // Access: Published 00090 // Description: This variant on acquire() accepts the current thread as 00091 // a parameter, if it is already known, as an 00092 // optimization. 00093 //////////////////////////////////////////////////////////////////// 00094 INLINE void LightReMutexDirect:: 00095 acquire(Thread *current_thread) const { 00096 TAU_PROFILE("void LightReMutexDirect::acquire(Thread *)", " ", TAU_USER); 00097 #ifdef HAVE_REMUTEXIMPL 00098 ((LightReMutexDirect *)this)->_impl.acquire(); 00099 #else 00100 ((LightReMutexDirect *)this)->_impl.do_lock(current_thread); 00101 #endif // HAVE_REMUTEXIMPL 00102 } 00103 00104 //////////////////////////////////////////////////////////////////// 00105 // Function: LightReMutexDirect::elevate_lock 00106 // Access: Published 00107 // Description: This method increments the lock count, assuming the 00108 // calling thread already holds the lock. After this 00109 // call, release() will need to be called one additional 00110 // time to release the lock. 00111 // 00112 // This method really performs the same function as 00113 // acquire(), but it offers a potential (slight) 00114 // performance benefit when the calling thread knows 00115 // that it already holds the lock. It is an error to 00116 // call this when the calling thread does not hold the 00117 // lock. 00118 //////////////////////////////////////////////////////////////////// 00119 INLINE void LightReMutexDirect:: 00120 elevate_lock() const { 00121 TAU_PROFILE("void LightReMutexDirect::elevate_lock()", " ", TAU_USER); 00122 #ifdef HAVE_REMUTEXIMPL 00123 ((LightReMutexDirect *)this)->_impl.acquire(); 00124 #else 00125 ((LightReMutexDirect *)this)->_impl.do_elevate_lock(); 00126 #endif // HAVE_REMUTEXIMPL 00127 } 00128 00129 //////////////////////////////////////////////////////////////////// 00130 // Function: LightReMutexDirect::release 00131 // Access: Published 00132 // Description: Releases the lightReMutex. It is an error to call this if 00133 // the lightReMutex was not already locked. 00134 // 00135 // This method is considered const so that you can lock 00136 // and unlock const lightReMutexes, mainly to allow thread-safe 00137 // access to otherwise const data. 00138 //////////////////////////////////////////////////////////////////// 00139 INLINE void LightReMutexDirect:: 00140 release() const { 00141 TAU_PROFILE("void LightReMutexDirect::release()", " ", TAU_USER); 00142 ((LightReMutexDirect *)this)->_impl.release(); 00143 } 00144 00145 //////////////////////////////////////////////////////////////////// 00146 // Function: LightReMutexDirect::debug_is_locked 00147 // Access: Published 00148 // Description: Returns true if the current thread has locked the 00149 // LightReMutex, false otherwise. This method is only intended 00150 // for use in debugging, hence the method name; in the 00151 // LightReMutexDirect case, it always returns true, since 00152 // there's not a reliable way to determine this 00153 // otherwise. 00154 //////////////////////////////////////////////////////////////////// 00155 INLINE bool LightReMutexDirect:: 00156 debug_is_locked() const { 00157 return true; 00158 } 00159 00160 //////////////////////////////////////////////////////////////////// 00161 // Function: LightReMutexDirect::set_name 00162 // Access: Public 00163 // Description: The mutex name is only defined when compiling in 00164 // DEBUG_THREADS mode. 00165 //////////////////////////////////////////////////////////////////// 00166 INLINE void LightReMutexDirect:: 00167 set_name(const string &) { 00168 } 00169 00170 //////////////////////////////////////////////////////////////////// 00171 // Function: LightReMutexDirect::clear_name 00172 // Access: Public 00173 // Description: The mutex name is only defined when compiling in 00174 // DEBUG_THREADS mode. 00175 //////////////////////////////////////////////////////////////////// 00176 INLINE void LightReMutexDirect:: 00177 clear_name() { 00178 } 00179 00180 //////////////////////////////////////////////////////////////////// 00181 // Function: LightReMutexDirect::has_name 00182 // Access: Public 00183 // Description: The mutex name is only defined when compiling in 00184 // DEBUG_THREADS mode. 00185 //////////////////////////////////////////////////////////////////// 00186 INLINE bool LightReMutexDirect:: 00187 has_name() const { 00188 return false; 00189 } 00190 00191 //////////////////////////////////////////////////////////////////// 00192 // Function: LightReMutexDirect::get_name 00193 // Access: Public 00194 // Description: The mutex name is only defined when compiling in 00195 // DEBUG_THREADS mode. 00196 //////////////////////////////////////////////////////////////////// 00197 INLINE string LightReMutexDirect:: 00198 get_name() const { 00199 return string(); 00200 }