00001 // Filename: mutexHolder.I 00002 // Created by: drose (09Aug02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: MutexHolder::Constructor 00022 // Access: Public 00023 // Description: 00024 //////////////////////////////////////////////////////////////////// 00025 INLINE MutexHolder:: 00026 MutexHolder(const Mutex &mutex) { 00027 #ifdef HAVE_THREADS 00028 _mutex = &mutex; 00029 _mutex->lock(); 00030 #endif 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: MutexHolder::Constructor 00035 // Access: Public 00036 // Description: If the MutexHolder constructor is given a pointer to 00037 // a Mutex object (instead of an actual object), it will 00038 // first check to see if the pointer is NULL, and 00039 // allocate a new Mutex if it is. This is intended as a 00040 // convenience for functions that may need to reference 00041 // a Mutex at static init time, when it is impossible to 00042 // guarantee ordering of initializers. 00043 //////////////////////////////////////////////////////////////////// 00044 INLINE MutexHolder:: 00045 MutexHolder(Mutex *&mutex) { 00046 #ifdef HAVE_THREADS 00047 if (mutex == (Mutex *)NULL) { 00048 mutex = new Mutex; 00049 } 00050 _mutex = mutex; 00051 _mutex->lock(); 00052 #endif 00053 } 00054 00055 //////////////////////////////////////////////////////////////////// 00056 // Function: MutexHolder::Destructor 00057 // Access: Public 00058 // Description: 00059 //////////////////////////////////////////////////////////////////// 00060 INLINE MutexHolder:: 00061 ~MutexHolder() { 00062 #ifdef HAVE_THREADS 00063 _mutex->release(); 00064 #endif 00065 } 00066 00067 //////////////////////////////////////////////////////////////////// 00068 // Function: MutexHolder::Copy Constructor 00069 // Access: Private 00070 // Description: Do not attempt to copy MutexHolders. 00071 //////////////////////////////////////////////////////////////////// 00072 INLINE MutexHolder:: 00073 MutexHolder(const MutexHolder ©) { 00074 nassertv(false); 00075 } 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Function: MutexHolder::Copy Assignment Operator 00079 // Access: Private 00080 // Description: Do not attempt to copy MutexHolders. 00081 //////////////////////////////////////////////////////////////////// 00082 INLINE void MutexHolder:: 00083 operator = (const MutexHolder ©) { 00084 nassertv(false); 00085 }