Panda3D

Loading...
Searching...
No Matches
lightReMutexDirect.I
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file lightReMutexDirect.I
10 * @author drose
11 * @date 2008-10-08
12 */
13
14/**
15 * Alias for acquire() to match C++11 semantics.
16 * @see acquire()
17 */
18INLINE void LightReMutexDirect::
19 lock() {
20 TAU_PROFILE("void LightReMutexDirect::acquire()", " ", TAU_USER);
21 _impl.lock();
22}
23
24/**
25 * Alias for try_acquire() to match C++11 semantics.
26 * @see try_acquire()
27 */
28INLINE bool LightReMutexDirect::
29 try_lock() {
30 TAU_PROFILE("void LightReMutexDirect::try_acquire()", " ", TAU_USER);
31 return _impl.try_lock();
32}
33
34/**
35 * Alias for release() to match C++11 semantics.
36 * @see release()
37 */
38INLINE void LightReMutexDirect::
39 unlock() {
40 TAU_PROFILE("void LightReMutexDirect::unlock()", " ", TAU_USER);
41 _impl.unlock();
42}
43
44/**
45 * Grabs the lightReMutex if it is available. If it is not available, blocks
46 * until it becomes available, then grabs it. In either case, the function
47 * does not return until the lightReMutex is held; you should then call
48 * unlock().
49 *
50 * This method is considered const so that you can lock and unlock const
51 * lightReMutexes, mainly to allow thread-safe access to otherwise const data.
52 *
53 * Also see LightReMutexHolder.
54 */
55INLINE void LightReMutexDirect::
56 acquire() const {
57 TAU_PROFILE("void LightReMutexDirect::acquire()", " ", TAU_USER);
58#ifdef HAVE_REMUTEXTRUEIMPL
59 _impl.lock();
60#else
61 _impl.do_lock(Thread::get_current_thread());
62#endif
63}
64
65/**
66 * This variant on acquire() accepts the current thread as a parameter, if it
67 * is already known, as an optimization.
68 */
69INLINE void LightReMutexDirect::
70 acquire(Thread *current_thread) const {
71 TAU_PROFILE("void LightReMutexDirect::acquire(Thread *)", " ", TAU_USER);
72#ifdef HAVE_REMUTEXTRUEIMPL
73 _impl.lock();
74#else
75 _impl.do_lock(current_thread);
76#endif // HAVE_REMUTEXIMPL
77}
78
79/**
80 * This method increments the lock count, assuming the calling thread already
81 * holds the lock. After this call, release() will need to be called one
82 * additional time to release the lock.
83 *
84 * This method really performs the same function as acquire(), but it offers a
85 * potential (slight) performance benefit when the calling thread knows that
86 * it already holds the lock. It is an error to call this when the calling
87 * thread does not hold the lock.
88 */
89INLINE void LightReMutexDirect::
90 elevate_lock() const {
91 TAU_PROFILE("void LightReMutexDirect::elevate_lock()", " ", TAU_USER);
92#ifdef HAVE_REMUTEXTRUEIMPL
93 _impl.lock();
94#else
95 _impl.do_elevate_lock();
96#endif // HAVE_REMUTEXIMPL
97}
98
99/**
100 * Releases the lightReMutex. It is an error to call this if the lightReMutex
101 * was not already locked.
102 *
103 * This method is considered const so that you can lock and unlock const
104 * lightReMutexes, mainly to allow thread-safe access to otherwise const data.
105 */
106INLINE void LightReMutexDirect::
107 release() const {
108 TAU_PROFILE("void LightReMutexDirect::release()", " ", TAU_USER);
109#ifdef HAVE_REMUTEXTRUEIMPL
110 _impl.unlock();
111#else
112 _impl.do_unlock(Thread::get_current_thread());
113#endif
114}
115
116/**
117 * Returns true if the current thread has locked the LightReMutex, false
118 * otherwise. This method is only intended for use in debugging, hence the
119 * method name; in the LightReMutexDirect case, it always returns true, since
120 * there's not a reliable way to determine this otherwise.
121 */
122INLINE bool LightReMutexDirect::
123 debug_is_locked() const {
124 return true;
125}
126
127/**
128 * The mutex name is only defined when compiling in DEBUG_THREADS mode.
129 */
130INLINE void LightReMutexDirect::
131 set_name(const std::string &) {
132}
133
134/**
135 * The mutex name is only defined when compiling in DEBUG_THREADS mode.
136 */
137INLINE void LightReMutexDirect::
138 clear_name() {
139}
140
141/**
142 * The mutex name is only defined when compiling in DEBUG_THREADS mode.
143 */
144INLINE bool LightReMutexDirect::
145 has_name() const {
146 return false;
147}
148
149/**
150 * The mutex name is only defined when compiling in DEBUG_THREADS mode.
151 */
152INLINE std::string LightReMutexDirect::
153 get_name() const {
154 return std::string();
155}
LightReMutexDirect::set_name
void set_name(const std::string &name)
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition lightReMutexDirect.I:131
LightReMutexDirect::acquire
void acquire() const
Grabs the lightReMutex if it is available.
Definition lightReMutexDirect.I:56
LightReMutexDirect::clear_name
void clear_name()
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition lightReMutexDirect.I:138
LightReMutexDirect::get_name
std::string get_name() const
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition lightReMutexDirect.I:153
LightReMutexDirect::debug_is_locked
bool debug_is_locked() const
Returns true if the current thread has locked the LightReMutex, false otherwise.
Definition lightReMutexDirect.I:123
LightReMutexDirect::try_lock
bool try_lock()
Alias for try_acquire() to match C++11 semantics.
Definition lightReMutexDirect.I:29
LightReMutexDirect::elevate_lock
void elevate_lock() const
This method increments the lock count, assuming the calling thread already holds the lock.
Definition lightReMutexDirect.I:90
LightReMutexDirect::unlock
void unlock()
Alias for release() to match C++11 semantics.
Definition lightReMutexDirect.I:39
LightReMutexDirect::release
void release() const
Releases the lightReMutex.
Definition lightReMutexDirect.I:107
LightReMutexDirect::lock
void lock()
Alias for acquire() to match C++11 semantics.
Definition lightReMutexDirect.I:19
LightReMutexDirect::has_name
bool has_name() const
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition lightReMutexDirect.I:145
Thread
A thread; that is, a lightweight process.
Definition thread.h:46
Thread::get_current_thread
get_current_thread
Returns a pointer to the currently-executing Thread object.
Definition thread.h:109