Panda3D
mutexDirect.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 mutexDirect.I
10  * @author drose
11  * @date 2006-02-13
12  */
13 
14 /**
15  * Alias for acquire() to match C++11 semantics.
16  * @see acquire()
17  */
18 INLINE void MutexDirect::
19 lock() {
20  TAU_PROFILE("void MutexDirect::acquire()", " ", TAU_USER);
21  _impl.lock();
22 }
23 
24 /**
25  * Alias for try_acquire() to match C++11 semantics.
26  * @see try_acquire()
27  */
28 INLINE bool MutexDirect::
30  TAU_PROFILE("void MutexDirect::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  */
38 INLINE void MutexDirect::
39 unlock() {
40  TAU_PROFILE("void MutexDirect::unlock()", " ", TAU_USER);
41  _impl.unlock();
42 }
43 
44 /**
45  * Grabs the mutex if it is available. If it is not available, blocks until
46  * it becomes available, then grabs it. In either case, the function does not
47  * return until the mutex is held; you should then call unlock().
48  *
49  * This method is considered const so that you can lock and unlock const
50  * mutexes, mainly to allow thread-safe access to otherwise const data.
51  *
52  * Also see MutexHolder.
53  */
54 INLINE void MutexDirect::
55 acquire() const {
56  TAU_PROFILE("void MutexDirect::acquire()", " ", TAU_USER);
57  _impl.lock();
58 }
59 
60 /**
61  * Returns immediately, with a true value indicating the mutex has been
62  * acquired, and false indicating it has not.
63  */
64 INLINE bool MutexDirect::
65 try_acquire() const {
66  TAU_PROFILE("void MutexDirect::acquire(bool)", " ", TAU_USER);
67  return _impl.try_lock();
68 }
69 
70 /**
71  * Releases the mutex. It is an error to call this if the mutex was not
72  * already locked.
73  *
74  * This method is considered const so that you can lock and unlock const
75  * mutexes, mainly to allow thread-safe access to otherwise const data.
76  */
77 INLINE void MutexDirect::
78 release() const {
79  TAU_PROFILE("void MutexDirect::release()", " ", TAU_USER);
80  _impl.unlock();
81 }
82 
83 /**
84  * Returns true if the current thread has locked the Mutex, false otherwise.
85  * This method is only intended for use in debugging, hence the method name;
86  * in the MutexDirect case, it always returns true, since there's not a
87  * reliable way to determine this otherwise.
88  */
89 INLINE bool MutexDirect::
90 debug_is_locked() const {
91  return true;
92 }
93 
94 /**
95  * The mutex name is only defined when compiling in DEBUG_THREADS mode.
96  */
97 INLINE void MutexDirect::
98 set_name(const std::string &) {
99 }
100 
101 /**
102  * The mutex name is only defined when compiling in DEBUG_THREADS mode.
103  */
104 INLINE void MutexDirect::
106 }
107 
108 /**
109  * The mutex name is only defined when compiling in DEBUG_THREADS mode.
110  */
111 INLINE bool MutexDirect::
112 has_name() const {
113  return false;
114 }
115 
116 /**
117  * The mutex name is only defined when compiling in DEBUG_THREADS mode.
118  */
119 INLINE std::string MutexDirect::
120 get_name() const {
121  return std::string();
122 }
void unlock()
Alias for release() to match C++11 semantics.
Definition: mutexDirect.I:39
std::string get_name() const
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition: mutexDirect.I:120
void set_name(const std::string &name)
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition: mutexDirect.I:98
void acquire() const
Grabs the mutex if it is available.
Definition: mutexDirect.I:55
bool try_acquire() const
Returns immediately, with a true value indicating the mutex has been acquired, and false indicating i...
Definition: mutexDirect.I:65
bool debug_is_locked() const
Returns true if the current thread has locked the Mutex, false otherwise.
Definition: mutexDirect.I:90
bool try_lock()
Alias for try_acquire() to match C++11 semantics.
Definition: mutexDirect.I:29
bool has_name() const
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition: mutexDirect.I:112
void release() const
Releases the mutex.
Definition: mutexDirect.I:78
void lock()
Alias for acquire() to match C++11 semantics.
Definition: mutexDirect.I:19
void clear_name()
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition: mutexDirect.I:105