Panda3D
 All Classes Functions Variables Enumerations
lightMutexHolder.I
1 // Filename: lightMutexHolder.I
2 // Created by: drose (08Oct08)
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: LightMutexHolder::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE LightMutexHolder::
22 LightMutexHolder(const LightMutex &mutex) {
23 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
24  _mutex = &mutex;
25  _mutex->acquire();
26 #endif
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: LightMutexHolder::Constructor
31 // Access: Public
32 // Description: If the LightMutexHolder constructor is given a pointer to
33 // a LightMutex object (instead of an actual object), it will
34 // first check to see if the pointer is NULL, and
35 // allocate a new LightMutex if it is. This is intended as a
36 // convenience for functions that may need to reference
37 // a LightMutex at static init time, when it is impossible to
38 // guarantee ordering of initializers.
39 ////////////////////////////////////////////////////////////////////
40 INLINE LightMutexHolder::
41 LightMutexHolder(LightMutex *&mutex) {
42 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
43  if (mutex == (LightMutex *)NULL) {
44  mutex = new LightMutex;
45  }
46  _mutex = mutex;
47  _mutex->acquire();
48 #endif
49 }
50 
51 ////////////////////////////////////////////////////////////////////
52 // Function: LightMutexHolder::Destructor
53 // Access: Public
54 // Description:
55 ////////////////////////////////////////////////////////////////////
56 INLINE LightMutexHolder::
57 ~LightMutexHolder() {
58 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
59  _mutex->release();
60 #endif
61 }
62 
63 ////////////////////////////////////////////////////////////////////
64 // Function: LightMutexHolder::Copy Constructor
65 // Access: Private
66 // Description: Do not attempt to copy LightMutexHolders.
67 ////////////////////////////////////////////////////////////////////
68 INLINE LightMutexHolder::
69 LightMutexHolder(const LightMutexHolder &copy) {
70  nassertv(false);
71 }
72 
73 ////////////////////////////////////////////////////////////////////
74 // Function: LightMutexHolder::Copy Assignment Operator
75 // Access: Private
76 // Description: Do not attempt to copy LightMutexHolders.
77 ////////////////////////////////////////////////////////////////////
78 INLINE void LightMutexHolder::
79 operator = (const LightMutexHolder &copy) {
80  nassertv(false);
81 }
void acquire() const
Grabs the lightMutex if it is available.
Similar to MutexHolder, but for a light mutex.
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:45