Panda3D
lightReMutexDirect.I
1 // Filename: lightReMutexDirect.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: LightReMutexDirect::Constructor
18 // Access: Protected
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE LightReMutexDirect::
22 LightReMutexDirect()
23 #ifndef HAVE_REMUTEXIMPL
24  : _cvar_impl(_lock_impl)
25 #endif
26 {
27 #ifndef HAVE_REMUTEXIMPL
28  _locking_thread = NULL;
29  _lock_count = 0;
30 #endif
31 }
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function: LightReMutexDirect::Destructor
35 // Access: Protected
36 // Description:
37 ////////////////////////////////////////////////////////////////////
38 INLINE LightReMutexDirect::
39 ~LightReMutexDirect() {
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: LightReMutexDirect::Copy Constructor
44 // Access: Private
45 // Description: Do not attempt to copy lightReMutexes.
46 ////////////////////////////////////////////////////////////////////
47 INLINE LightReMutexDirect::
48 LightReMutexDirect(const LightReMutexDirect &copy)
49 #ifndef HAVE_REMUTEXIMPL
50  : _cvar_impl(_lock_impl)
51 #endif
52 {
53  nassertv(false);
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: LightReMutexDirect::Copy Assignment Operator
58 // Access: Private
59 // Description: Do not attempt to copy lightReMutexes.
60 ////////////////////////////////////////////////////////////////////
61 INLINE void LightReMutexDirect::
62 operator = (const LightReMutexDirect &copy) {
63  nassertv(false);
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: LightReMutexDirect::acquire
68 // Access: Published
69 // Description: Grabs the lightReMutex if it is available. If it is not
70 // available, blocks until it becomes available, then
71 // grabs it. In either case, the function does not
72 // return until the lightReMutex is held; you should then call
73 // unlock().
74 //
75 // This method is considered const so that you can lock
76 // and unlock const lightReMutexes, mainly to allow thread-safe
77 // access to otherwise const data.
78 //
79 // Also see LightReMutexHolder.
80 ////////////////////////////////////////////////////////////////////
81 INLINE void LightReMutexDirect::
82 acquire() const {
83  TAU_PROFILE("void LightReMutexDirect::acquire()", " ", TAU_USER);
84  ((LightReMutexDirect *)this)->_impl.acquire();
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: LightReMutexDirect::acquire
89 // Access: Published
90 // Description: This variant on acquire() accepts the current thread as
91 // a parameter, if it is already known, as an
92 // optimization.
93 ////////////////////////////////////////////////////////////////////
94 INLINE void LightReMutexDirect::
95 acquire(Thread *current_thread) const {
96  TAU_PROFILE("void LightReMutexDirect::acquire(Thread *)", " ", TAU_USER);
97 #ifdef HAVE_REMUTEXIMPL
98  ((LightReMutexDirect *)this)->_impl.acquire();
99 #else
100  ((LightReMutexDirect *)this)->_impl.do_lock(current_thread);
101 #endif // HAVE_REMUTEXIMPL
102 }
103 
104 ////////////////////////////////////////////////////////////////////
105 // Function: LightReMutexDirect::elevate_lock
106 // Access: Published
107 // Description: This method increments the lock count, assuming the
108 // calling thread already holds the lock. After this
109 // call, release() will need to be called one additional
110 // time to release the lock.
111 //
112 // This method really performs the same function as
113 // acquire(), but it offers a potential (slight)
114 // performance benefit when the calling thread knows
115 // that it already holds the lock. It is an error to
116 // call this when the calling thread does not hold the
117 // lock.
118 ////////////////////////////////////////////////////////////////////
119 INLINE void LightReMutexDirect::
120 elevate_lock() const {
121  TAU_PROFILE("void LightReMutexDirect::elevate_lock()", " ", TAU_USER);
122 #ifdef HAVE_REMUTEXIMPL
123  ((LightReMutexDirect *)this)->_impl.acquire();
124 #else
125  ((LightReMutexDirect *)this)->_impl.do_elevate_lock();
126 #endif // HAVE_REMUTEXIMPL
127 }
128 
129 ////////////////////////////////////////////////////////////////////
130 // Function: LightReMutexDirect::release
131 // Access: Published
132 // Description: Releases the lightReMutex. It is an error to call this if
133 // the lightReMutex was not already locked.
134 //
135 // This method is considered const so that you can lock
136 // and unlock const lightReMutexes, mainly to allow thread-safe
137 // access to otherwise const data.
138 ////////////////////////////////////////////////////////////////////
139 INLINE void LightReMutexDirect::
140 release() const {
141  TAU_PROFILE("void LightReMutexDirect::release()", " ", TAU_USER);
142  ((LightReMutexDirect *)this)->_impl.release();
143 }
144 
145 ////////////////////////////////////////////////////////////////////
146 // Function: LightReMutexDirect::debug_is_locked
147 // Access: Published
148 // Description: Returns true if the current thread has locked the
149 // LightReMutex, false otherwise. This method is only intended
150 // for use in debugging, hence the method name; in the
151 // LightReMutexDirect case, it always returns true, since
152 // there's not a reliable way to determine this
153 // otherwise.
154 ////////////////////////////////////////////////////////////////////
155 INLINE bool LightReMutexDirect::
157  return true;
158 }
159 
160 ////////////////////////////////////////////////////////////////////
161 // Function: LightReMutexDirect::set_name
162 // Access: Public
163 // Description: The mutex name is only defined when compiling in
164 // DEBUG_THREADS mode.
165 ////////////////////////////////////////////////////////////////////
166 INLINE void LightReMutexDirect::
167 set_name(const string &) {
168 }
169 
170 ////////////////////////////////////////////////////////////////////
171 // Function: LightReMutexDirect::clear_name
172 // Access: Public
173 // Description: The mutex name is only defined when compiling in
174 // DEBUG_THREADS mode.
175 ////////////////////////////////////////////////////////////////////
176 INLINE void LightReMutexDirect::
178 }
179 
180 ////////////////////////////////////////////////////////////////////
181 // Function: LightReMutexDirect::has_name
182 // Access: Public
183 // Description: The mutex name is only defined when compiling in
184 // DEBUG_THREADS mode.
185 ////////////////////////////////////////////////////////////////////
186 INLINE bool LightReMutexDirect::
187 has_name() const {
188  return false;
189 }
190 
191 ////////////////////////////////////////////////////////////////////
192 // Function: LightReMutexDirect::get_name
193 // Access: Public
194 // Description: The mutex name is only defined when compiling in
195 // DEBUG_THREADS mode.
196 ////////////////////////////////////////////////////////////////////
197 INLINE string LightReMutexDirect::
198 get_name() const {
199  return string();
200 }
void set_name(const string &name)
The mutex name is only defined when compiling in DEBUG_THREADS mode.
bool has_name() const
The mutex name is only defined when compiling in DEBUG_THREADS mode.
This class implements a standard lightReMutex by making direct calls to the underlying implementation...
bool debug_is_locked() const
Returns true if the current thread has locked the LightReMutex, false otherwise.
void release() const
Releases the lightReMutex.
string get_name() const
The mutex name is only defined when compiling in DEBUG_THREADS mode.
void elevate_lock() const
This method increments the lock count, assuming the calling thread already holds the lock...
A thread; that is, a lightweight process.
Definition: thread.h:51
void acquire() const
Grabs the lightReMutex if it is available.
void clear_name()
The mutex name is only defined when compiling in DEBUG_THREADS mode.