Panda3D
|
00001 // Filename: mutexHolder.I 00002 // Created by: drose (09Aug02) 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: MutexHolder::Constructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE MutexHolder:: 00022 MutexHolder(const Mutex &mutex) { 00023 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) 00024 _mutex = &mutex; 00025 _mutex->acquire(); 00026 #endif 00027 } 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function: MutexHolder::Constructor 00031 // Access: Public 00032 // Description: If the MutexHolder constructor is given a pointer to 00033 // a Mutex object (instead of an actual object), it will 00034 // first check to see if the pointer is NULL, and 00035 // allocate a new Mutex if it is. This is intended as a 00036 // convenience for functions that may need to reference 00037 // a Mutex at static init time, when it is impossible to 00038 // guarantee ordering of initializers. 00039 //////////////////////////////////////////////////////////////////// 00040 INLINE MutexHolder:: 00041 MutexHolder(Mutex *&mutex) { 00042 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) 00043 if (mutex == (Mutex *)NULL) { 00044 mutex = new Mutex; 00045 } 00046 _mutex = mutex; 00047 _mutex->acquire(); 00048 #endif 00049 } 00050 00051 //////////////////////////////////////////////////////////////////// 00052 // Function: MutexHolder::Destructor 00053 // Access: Public 00054 // Description: 00055 //////////////////////////////////////////////////////////////////// 00056 INLINE MutexHolder:: 00057 ~MutexHolder() { 00058 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) 00059 _mutex->release(); 00060 #endif 00061 } 00062 00063 //////////////////////////////////////////////////////////////////// 00064 // Function: MutexHolder::Copy Constructor 00065 // Access: Private 00066 // Description: Do not attempt to copy MutexHolders. 00067 //////////////////////////////////////////////////////////////////// 00068 INLINE MutexHolder:: 00069 MutexHolder(const MutexHolder ©) { 00070 nassertv(false); 00071 } 00072 00073 //////////////////////////////////////////////////////////////////// 00074 // Function: MutexHolder::Copy Assignment Operator 00075 // Access: Private 00076 // Description: Do not attempt to copy MutexHolders. 00077 //////////////////////////////////////////////////////////////////// 00078 INLINE void MutexHolder:: 00079 operator = (const MutexHolder ©) { 00080 nassertv(false); 00081 }