Panda3D

mutexHolder.h

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(Mutex *&mutex);
00033   INLINE ~MutexHolder();
00034 private:
00035   INLINE MutexHolder(const MutexHolder &copy);
00036   INLINE void operator = (const MutexHolder &copy);
00037 
00038 private:
00039   // If HAVE_THREADS is defined, the Mutex class implements an actual
00040   // mutex object of some kind.  If HAVE_THREADS is not defined, this
00041   // will be a MutexDummyImpl, which does nothing much anyway, so we
00042   // might as well not even store a pointer to one.
00043 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
00044   const Mutex *_mutex;
00045 #endif
00046 };
00047 
00048 #include "mutexHolder.I"
00049 
00050 #endif
 All Classes Functions Variables Enumerations