Panda3D
|
00001 // Filename: reMutexDirect.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: ReMutexDirect::Constructor 00018 // Access: Protected 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE ReMutexDirect:: 00022 ReMutexDirect() 00023 #ifndef HAVE_REMUTEXTRUEIMPL 00024 : _cvar_impl(_lock_impl) 00025 #endif 00026 { 00027 #ifndef HAVE_REMUTEXTRUEIMPL 00028 _locking_thread = NULL; 00029 _lock_count = 0; 00030 #endif 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: ReMutexDirect::Destructor 00035 // Access: Protected 00036 // Description: 00037 //////////////////////////////////////////////////////////////////// 00038 INLINE ReMutexDirect:: 00039 ~ReMutexDirect() { 00040 } 00041 00042 //////////////////////////////////////////////////////////////////// 00043 // Function: ReMutexDirect::Copy Constructor 00044 // Access: Private 00045 // Description: Do not attempt to copy reMutexes. 00046 //////////////////////////////////////////////////////////////////// 00047 INLINE ReMutexDirect:: 00048 ReMutexDirect(const ReMutexDirect ©) 00049 #ifndef HAVE_REMUTEXTRUEIMPL 00050 : _cvar_impl(_lock_impl) 00051 #endif 00052 { 00053 nassertv(false); 00054 } 00055 00056 //////////////////////////////////////////////////////////////////// 00057 // Function: ReMutexDirect::Copy Assignment Operator 00058 // Access: Private 00059 // Description: Do not attempt to copy reMutexes. 00060 //////////////////////////////////////////////////////////////////// 00061 INLINE void ReMutexDirect:: 00062 operator = (const ReMutexDirect ©) { 00063 nassertv(false); 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: ReMutexDirect::acquire 00068 // Access: Published 00069 // Description: Grabs the reMutex 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 reMutex is held; you should then call 00073 // unlock(). 00074 // 00075 // This method is considered const so that you can lock 00076 // and unlock const reMutexes, mainly to allow thread-safe 00077 // access to otherwise const data. 00078 // 00079 // Also see ReMutexHolder. 00080 //////////////////////////////////////////////////////////////////// 00081 INLINE void ReMutexDirect:: 00082 acquire() const { 00083 TAU_PROFILE("void ReMutexDirect::acquire()", " ", TAU_USER); 00084 #ifdef HAVE_REMUTEXTRUEIMPL 00085 ((ReMutexDirect *)this)->_impl.acquire(); 00086 #else 00087 ((ReMutexDirect *)this)->do_acquire(); 00088 #endif // HAVE_REMUTEXTRUEIMPL 00089 } 00090 00091 //////////////////////////////////////////////////////////////////// 00092 // Function: ReMutexDirect::acquire 00093 // Access: Published 00094 // Description: This variant on acquire() accepts the current thread as 00095 // a parameter, if it is already known, as an 00096 // optimization. 00097 //////////////////////////////////////////////////////////////////// 00098 INLINE void ReMutexDirect:: 00099 acquire(Thread *current_thread) const { 00100 TAU_PROFILE("void ReMutexDirect::acquire(Thread *)", " ", TAU_USER); 00101 #ifdef HAVE_REMUTEXTRUEIMPL 00102 ((ReMutexDirect *)this)->_impl.acquire(); 00103 #else 00104 ((ReMutexDirect *)this)->do_acquire(current_thread); 00105 #endif // HAVE_REMUTEXTRUEIMPL 00106 } 00107 00108 //////////////////////////////////////////////////////////////////// 00109 // Function: ReMutexDirect::try_acquire 00110 // Access: Published 00111 // Description: Returns immediately, with a true value indicating the 00112 // mutex has been acquired, and false indicating it has 00113 // not. 00114 //////////////////////////////////////////////////////////////////// 00115 INLINE bool ReMutexDirect:: 00116 try_acquire() const { 00117 TAU_PROFILE("void ReMutexDirect::acquire(bool)", " ", TAU_USER); 00118 #ifdef HAVE_REMUTEXTRUEIMPL 00119 return ((ReMutexDirect *)this)->_impl.try_acquire(); 00120 #else 00121 return ((ReMutexDirect *)this)->do_try_acquire(); 00122 #endif // HAVE_REMUTEXTRUEIMPL 00123 } 00124 00125 //////////////////////////////////////////////////////////////////// 00126 // Function: ReMutexDirect::try_acquire 00127 // Access: Published 00128 // Description: Returns immediately, with a true value indicating the 00129 // mutex has been acquired, and false indicating it has 00130 // not. 00131 //////////////////////////////////////////////////////////////////// 00132 INLINE bool ReMutexDirect:: 00133 try_acquire(Thread *current_thread) const { 00134 TAU_PROFILE("void ReMutexDirect::acquire(bool)", " ", TAU_USER); 00135 #ifdef HAVE_REMUTEXTRUEIMPL 00136 return ((ReMutexDirect *)this)->_impl.try_acquire(); 00137 #else 00138 return ((ReMutexDirect *)this)->do_try_acquire(current_thread); 00139 #endif // HAVE_REMUTEXTRUEIMPL 00140 } 00141 00142 //////////////////////////////////////////////////////////////////// 00143 // Function: ReMutexDirect::elevate_lock 00144 // Access: Published 00145 // Description: This method increments the lock count, assuming the 00146 // calling thread already holds the lock. After this 00147 // call, release() will need to be called one additional 00148 // time to release the lock. 00149 // 00150 // This method really performs the same function as 00151 // acquire(), but it offers a potential (slight) 00152 // performance benefit when the calling thread knows 00153 // that it already holds the lock. It is an error to 00154 // call this when the calling thread does not hold the 00155 // lock. 00156 //////////////////////////////////////////////////////////////////// 00157 INLINE void ReMutexDirect:: 00158 elevate_lock() const { 00159 TAU_PROFILE("void ReMutexDirect::elevate_lock()", " ", TAU_USER); 00160 #ifdef HAVE_REMUTEXTRUEIMPL 00161 ((ReMutexDirect *)this)->_impl.acquire(); 00162 #else 00163 ((ReMutexDirect *)this)->do_elevate_lock(); 00164 #endif // HAVE_REMUTEXTRUEIMPL 00165 } 00166 00167 //////////////////////////////////////////////////////////////////// 00168 // Function: ReMutexDirect::release 00169 // Access: Published 00170 // Description: Releases the reMutex. It is an error to call this if 00171 // the reMutex was not already locked. 00172 // 00173 // This method is considered const so that you can lock 00174 // and unlock const reMutexes, mainly to allow thread-safe 00175 // access to otherwise const data. 00176 //////////////////////////////////////////////////////////////////// 00177 INLINE void ReMutexDirect:: 00178 release() const { 00179 TAU_PROFILE("void ReMutexDirect::release()", " ", TAU_USER); 00180 #ifdef HAVE_REMUTEXTRUEIMPL 00181 ((ReMutexDirect *)this)->_impl.release(); 00182 #else 00183 ((ReMutexDirect *)this)->do_release(); 00184 #endif // HAVE_REMUTEXTRUEIMPL 00185 } 00186 00187 //////////////////////////////////////////////////////////////////// 00188 // Function: ReMutexDirect::debug_is_locked 00189 // Access: Published 00190 // Description: Returns true if the current thread has locked the 00191 // ReMutex, false otherwise. This method is only intended 00192 // for use in debugging, hence the method name; in the 00193 // ReMutexDirect case, it always returns true, since 00194 // there's not a reliable way to determine this 00195 // otherwise. 00196 //////////////////////////////////////////////////////////////////// 00197 INLINE bool ReMutexDirect:: 00198 debug_is_locked() const { 00199 return true; 00200 } 00201 00202 //////////////////////////////////////////////////////////////////// 00203 // Function: ReMutexDirect::set_name 00204 // Access: Public 00205 // Description: The mutex name is only defined when compiling in 00206 // DEBUG_THREADS mode. 00207 //////////////////////////////////////////////////////////////////// 00208 INLINE void ReMutexDirect:: 00209 set_name(const string &) { 00210 } 00211 00212 //////////////////////////////////////////////////////////////////// 00213 // Function: ReMutexDirect::clear_name 00214 // Access: Public 00215 // Description: The mutex name is only defined when compiling in 00216 // DEBUG_THREADS mode. 00217 //////////////////////////////////////////////////////////////////// 00218 INLINE void ReMutexDirect:: 00219 clear_name() { 00220 } 00221 00222 //////////////////////////////////////////////////////////////////// 00223 // Function: ReMutexDirect::has_name 00224 // Access: Public 00225 // Description: The mutex name is only defined when compiling in 00226 // DEBUG_THREADS mode. 00227 //////////////////////////////////////////////////////////////////// 00228 INLINE bool ReMutexDirect:: 00229 has_name() const { 00230 return false; 00231 } 00232 00233 //////////////////////////////////////////////////////////////////// 00234 // Function: ReMutexDirect::get_name 00235 // Access: Public 00236 // Description: The mutex name is only defined when compiling in 00237 // DEBUG_THREADS mode. 00238 //////////////////////////////////////////////////////////////////// 00239 INLINE string ReMutexDirect:: 00240 get_name() const { 00241 return string(); 00242 } 00243 00244 #ifndef HAVE_REMUTEXTRUEIMPL 00245 //////////////////////////////////////////////////////////////////// 00246 // Function: ReMutexDirect::do_acquire 00247 // Access: Private 00248 // Description: The private implementation of acquire(), for the case in 00249 // which the underlying lock system does not provide a 00250 // reentrant mutex (and therefore we have to build this 00251 // functionality on top of the existing non-reentrant 00252 // mutex). 00253 //////////////////////////////////////////////////////////////////// 00254 INLINE void ReMutexDirect:: 00255 do_acquire() { 00256 do_acquire(Thread::get_current_thread()); 00257 } 00258 #endif 00259 00260 #ifndef HAVE_REMUTEXTRUEIMPL 00261 //////////////////////////////////////////////////////////////////// 00262 // Function: ReMutexDirect::do_try_acquire 00263 // Access: Private 00264 // Description: The private implementation of acquire(false), for the 00265 // case in which the underlying lock system does not 00266 // provide a reentrant mutex (and therefore we have to 00267 // build this functionality on top of the existing 00268 // non-reentrant mutex). 00269 //////////////////////////////////////////////////////////////////// 00270 INLINE bool ReMutexDirect:: 00271 do_try_acquire() { 00272 return do_try_acquire(Thread::get_current_thread()); 00273 } 00274 #endif 00275