Panda3D
 All Classes Functions Variables Enumerations
lightReMutexHolder.I
1 // Filename: lightReMutexHolder.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: LightReMutexHolder::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE LightReMutexHolder::
22 LightReMutexHolder(const LightReMutex &mutex) {
23 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
24  _mutex = &mutex;
25  _mutex->acquire();
26 #endif
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: LightReMutexHolder::Constructor
31 // Access: Public
32 // Description: This variant on the constructor accepts the current
33 // thread as a parameter, if it is already known, as an
34 // optimization.
35 ////////////////////////////////////////////////////////////////////
36 INLINE LightReMutexHolder::
37 LightReMutexHolder(const LightReMutex &mutex, Thread *current_thread) {
38 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
39  _mutex = &mutex;
40  _mutex->acquire(current_thread);
41 #endif
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: LightReMutexHolder::Constructor
46 // Access: Public
47 // Description: If the LightReMutexHolder constructor is given a pointer to
48 // a LightReMutex object (instead of an actual object), it will
49 // first check to see if the pointer is NULL, and
50 // allocate a new LightReMutex if it is. This is intended as a
51 // convenience for functions that may need to reference
52 // a LightReMutex at static init time, when it is impossible to
53 // guarantee ordering of initializers.
54 ////////////////////////////////////////////////////////////////////
55 INLINE LightReMutexHolder::
56 LightReMutexHolder(LightReMutex *&mutex) {
57 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
58  if (mutex == (LightReMutex *)NULL) {
59  mutex = new LightReMutex;
60  }
61  _mutex = mutex;
62  _mutex->acquire();
63 #endif
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: LightReMutexHolder::Destructor
68 // Access: Public
69 // Description:
70 ////////////////////////////////////////////////////////////////////
71 INLINE LightReMutexHolder::
72 ~LightReMutexHolder() {
73 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
74  _mutex->release();
75 #endif
76 }
77 
78 ////////////////////////////////////////////////////////////////////
79 // Function: LightReMutexHolder::Copy Constructor
80 // Access: Private
81 // Description: Do not attempt to copy LightReMutexHolders.
82 ////////////////////////////////////////////////////////////////////
83 INLINE LightReMutexHolder::
84 LightReMutexHolder(const LightReMutexHolder &copy) {
85  nassertv(false);
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: LightReMutexHolder::Copy Assignment Operator
90 // Access: Private
91 // Description: Do not attempt to copy LightReMutexHolders.
92 ////////////////////////////////////////////////////////////////////
93 INLINE void LightReMutexHolder::
94 operator = (const LightReMutexHolder &copy) {
95  nassertv(false);
96 }
A lightweight reentrant mutex.
Definition: lightReMutex.h:34
void acquire() const
Grabs the lightReMutex if it is available.
Similar to MutexHolder, but for a light reentrant mutex.
A thread; that is, a lightweight process.
Definition: thread.h:51