Panda3D
|
00001 // Filename: lightReMutexHolder.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: LightReMutexHolder::Constructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE LightReMutexHolder:: 00022 LightReMutexHolder(const LightReMutex &mutex) { 00023 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) 00024 _mutex = &mutex; 00025 _mutex->acquire(); 00026 #endif 00027 } 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function: LightReMutexHolder::Constructor 00031 // Access: Public 00032 // Description: This variant on the constructor accepts the current 00033 // thread as a parameter, if it is already known, as an 00034 // optimization. 00035 //////////////////////////////////////////////////////////////////// 00036 INLINE LightReMutexHolder:: 00037 LightReMutexHolder(const LightReMutex &mutex, Thread *current_thread) { 00038 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) 00039 _mutex = &mutex; 00040 _mutex->acquire(current_thread); 00041 #endif 00042 } 00043 00044 //////////////////////////////////////////////////////////////////// 00045 // Function: LightReMutexHolder::Constructor 00046 // Access: Public 00047 // Description: If the LightReMutexHolder constructor is given a pointer to 00048 // a LightReMutex object (instead of an actual object), it will 00049 // first check to see if the pointer is NULL, and 00050 // allocate a new LightReMutex if it is. This is intended as a 00051 // convenience for functions that may need to reference 00052 // a LightReMutex at static init time, when it is impossible to 00053 // guarantee ordering of initializers. 00054 //////////////////////////////////////////////////////////////////// 00055 INLINE LightReMutexHolder:: 00056 LightReMutexHolder(LightReMutex *&mutex) { 00057 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) 00058 if (mutex == (LightReMutex *)NULL) { 00059 mutex = new LightReMutex; 00060 } 00061 _mutex = mutex; 00062 _mutex->acquire(); 00063 #endif 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: LightReMutexHolder::Destructor 00068 // Access: Public 00069 // Description: 00070 //////////////////////////////////////////////////////////////////// 00071 INLINE LightReMutexHolder:: 00072 ~LightReMutexHolder() { 00073 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) 00074 _mutex->release(); 00075 #endif 00076 } 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function: LightReMutexHolder::Copy Constructor 00080 // Access: Private 00081 // Description: Do not attempt to copy LightReMutexHolders. 00082 //////////////////////////////////////////////////////////////////// 00083 INLINE LightReMutexHolder:: 00084 LightReMutexHolder(const LightReMutexHolder ©) { 00085 nassertv(false); 00086 } 00087 00088 //////////////////////////////////////////////////////////////////// 00089 // Function: LightReMutexHolder::Copy Assignment Operator 00090 // Access: Private 00091 // Description: Do not attempt to copy LightReMutexHolders. 00092 //////////////////////////////////////////////////////////////////// 00093 INLINE void LightReMutexHolder:: 00094 operator = (const LightReMutexHolder ©) { 00095 nassertv(false); 00096 }