Panda3D
reMutexHolder.I
1 // Filename: reMutexHolder.I
2 // Created by: drose (15Jan06)
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: ReMutexHolder::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE ReMutexHolder::
22 ReMutexHolder(const ReMutex &mutex) {
23 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
24  _mutex = &mutex;
25  _mutex->acquire();
26 #endif
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: ReMutexHolder::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 ReMutexHolder::
37 ReMutexHolder(const ReMutex &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: ReMutexHolder::Constructor
46 // Access: Public
47 // Description: If the ReMutexHolder constructor is given a pointer to
48 // a ReMutex object (instead of an actual object), it will
49 // first check to see if the pointer is NULL, and
50 // allocate a new ReMutex if it is. This is intended as a
51 // convenience for functions that may need to reference
52 // a ReMutex at static init time, when it is impossible to
53 // guarantee ordering of initializers.
54 ////////////////////////////////////////////////////////////////////
55 INLINE ReMutexHolder::
56 ReMutexHolder(ReMutex *&mutex) {
57 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
58  if (mutex == (ReMutex *)NULL) {
59  mutex = new ReMutex;
60  }
61  _mutex = mutex;
62  _mutex->acquire();
63 #endif
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: ReMutexHolder::Destructor
68 // Access: Public
69 // Description:
70 ////////////////////////////////////////////////////////////////////
71 INLINE ReMutexHolder::
72 ~ReMutexHolder() {
73 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
74  _mutex->release();
75 #endif
76 }
77 
78 ////////////////////////////////////////////////////////////////////
79 // Function: ReMutexHolder::Copy Constructor
80 // Access: Private
81 // Description: Do not attempt to copy ReMutexHolders.
82 ////////////////////////////////////////////////////////////////////
83 INLINE ReMutexHolder::
84 ReMutexHolder(const ReMutexHolder &copy) {
85  nassertv(false);
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: ReMutexHolder::Copy Assignment Operator
90 // Access: Private
91 // Description: Do not attempt to copy ReMutexHolders.
92 ////////////////////////////////////////////////////////////////////
93 INLINE void ReMutexHolder::
94 operator = (const ReMutexHolder &copy) {
95  nassertv(false);
96 }
void acquire() const
Grabs the reMutex if it is available.
Definition: reMutexDirect.I:82
Similar to MutexHolder, but for a reentrant mutex.
Definition: reMutexHolder.h:27
A thread; that is, a lightweight process.
Definition: thread.h:51
A reentrant mutex.
Definition: reMutex.h:36