00001 // Filename: mutexHolder.h 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 #ifndef MUTEXHOLDER_H 00020 #define MUTEXHOLDER_H 00021 00022 #include "pandabase.h" 00023 #include "pmutex.h" 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Class : MutexHolder 00027 // Description : A lightweight C++ object whose constructor calls 00028 // lock() and whose destructor calls release() on a 00029 // mutex. It is a C++ convenience wrapper to call 00030 // release() automatically when a block exits (for 00031 // instance, on return). 00032 //////////////////////////////////////////////////////////////////// 00033 class EXPCL_PANDA MutexHolder { 00034 public: 00035 INLINE MutexHolder(const Mutex &mutex); 00036 INLINE MutexHolder(Mutex *&mutex); 00037 INLINE ~MutexHolder(); 00038 private: 00039 INLINE MutexHolder(const MutexHolder ©); 00040 INLINE void operator = (const MutexHolder ©); 00041 00042 private: 00043 #ifdef HAVE_THREADS 00044 const Mutex *_mutex; 00045 #endif 00046 }; 00047 00048 #include "mutexHolder.I" 00049 00050 #endif