Panda3D
 All Classes Functions Variables Enumerations
mutexHolder.h
1 // Filename: mutexHolder.h
2 // Created by: drose (09Aug02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef MUTEXHOLDER_H
16 #define MUTEXHOLDER_H
17 
18 #include "pandabase.h"
19 #include "pmutex.h"
20 
21 ////////////////////////////////////////////////////////////////////
22 // Class : MutexHolder
23 // Description : A lightweight C++ object whose constructor calls
24 // acquire() and whose destructor calls release() on a
25 // mutex. It is a C++ convenience wrapper to call
26 // release() automatically when a block exits (for
27 // instance, on return).
28 ////////////////////////////////////////////////////////////////////
29 class EXPCL_PANDA_PIPELINE MutexHolder {
30 public:
31  INLINE MutexHolder(const Mutex &mutex);
32  INLINE MutexHolder(const Mutex &mutex, Thread *current_thread);
33  INLINE MutexHolder(Mutex *&mutex);
34  INLINE ~MutexHolder();
35 private:
36  INLINE MutexHolder(const MutexHolder &copy);
37  INLINE void operator = (const MutexHolder &copy);
38 
39 private:
40  // If HAVE_THREADS is defined, the Mutex class implements an actual
41  // mutex object of some kind. If HAVE_THREADS is not defined, this
42  // will be a MutexDummyImpl, which does nothing much anyway, so we
43  // might as well not even store a pointer to one.
44 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
45  const Mutex *_mutex;
46 #endif
47 };
48 
49 #include "mutexHolder.I"
50 
51 #endif
A standard mutex, or mutual exclusion lock.
Definition: pmutex.h:44
A lightweight C++ object whose constructor calls acquire() and whose destructor calls release() on a ...
Definition: mutexHolder.h:29
A thread; that is, a lightweight process.
Definition: thread.h:51