Panda3D
|
00001 // Filename: mutexHolder.h 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 #ifndef MUTEXHOLDER_H 00016 #define MUTEXHOLDER_H 00017 00018 #include "pandabase.h" 00019 #include "pmutex.h" 00020 00021 //////////////////////////////////////////////////////////////////// 00022 // Class : MutexHolder 00023 // Description : A lightweight C++ object whose constructor calls 00024 // acquire() and whose destructor calls release() on a 00025 // mutex. It is a C++ convenience wrapper to call 00026 // release() automatically when a block exits (for 00027 // instance, on return). 00028 //////////////////////////////////////////////////////////////////// 00029 class EXPCL_PANDA_PIPELINE MutexHolder { 00030 public: 00031 INLINE MutexHolder(const Mutex &mutex); 00032 INLINE MutexHolder(const Mutex &mutex, Thread *current_thread); 00033 INLINE MutexHolder(Mutex *&mutex); 00034 INLINE ~MutexHolder(); 00035 private: 00036 INLINE MutexHolder(const MutexHolder ©); 00037 INLINE void operator = (const MutexHolder ©); 00038 00039 private: 00040 // If HAVE_THREADS is defined, the Mutex class implements an actual 00041 // mutex object of some kind. If HAVE_THREADS is not defined, this 00042 // will be a MutexDummyImpl, which does nothing much anyway, so we 00043 // might as well not even store a pointer to one. 00044 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) 00045 const Mutex *_mutex; 00046 #endif 00047 }; 00048 00049 #include "mutexHolder.I" 00050 00051 #endif