Panda3D
 All Classes Functions Variables Enumerations
mutexDirect.I
1 // Filename: mutexDirect.I
2 // Created by: drose (13Feb06)
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: MutexDirect::Constructor
18 // Access: Protected
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE MutexDirect::
22 MutexDirect() {
23 }
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: MutexDirect::Destructor
27 // Access: Protected
28 // Description:
29 ////////////////////////////////////////////////////////////////////
30 INLINE MutexDirect::
31 ~MutexDirect() {
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: MutexDirect::Copy Constructor
36 // Access: Private
37 // Description: Do not attempt to copy mutexes.
38 ////////////////////////////////////////////////////////////////////
39 INLINE MutexDirect::
40 MutexDirect(const MutexDirect &copy) {
41  nassertv(false);
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: MutexDirect::Copy Assignment Operator
46 // Access: Private
47 // Description: Do not attempt to copy mutexes.
48 ////////////////////////////////////////////////////////////////////
49 INLINE void MutexDirect::
50 operator = (const MutexDirect &copy) {
51  nassertv(false);
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: MutexDirect::acquire
56 // Access: Published
57 // Description: Grabs the mutex if it is available. If it is not
58 // available, blocks until it becomes available, then
59 // grabs it. In either case, the function does not
60 // return until the mutex is held; you should then call
61 // unlock().
62 //
63 // This method is considered const so that you can lock
64 // and unlock const mutexes, mainly to allow thread-safe
65 // access to otherwise const data.
66 //
67 // Also see MutexHolder.
68 ////////////////////////////////////////////////////////////////////
69 INLINE void MutexDirect::
70 acquire() const {
71  TAU_PROFILE("void MutexDirect::acquire()", " ", TAU_USER);
72  ((MutexDirect *)this)->_impl.acquire();
73 }
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function: MutexDirect::try_acquire
77 // Access: Published
78 // Description: Returns immediately, with a true value indicating the
79 // mutex has been acquired, and false indicating it has
80 // not.
81 ////////////////////////////////////////////////////////////////////
82 INLINE bool MutexDirect::
83 try_acquire() const {
84  TAU_PROFILE("void MutexDirect::acquire(bool)", " ", TAU_USER);
85  return ((MutexDirect *)this)->_impl.try_acquire();
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: MutexDirect::release
90 // Access: Published
91 // Description: Releases the mutex. It is an error to call this if
92 // the mutex was not already locked.
93 //
94 // This method is considered const so that you can lock
95 // and unlock const mutexes, mainly to allow thread-safe
96 // access to otherwise const data.
97 ////////////////////////////////////////////////////////////////////
98 INLINE void MutexDirect::
99 release() const {
100  TAU_PROFILE("void MutexDirect::release()", " ", TAU_USER);
101  ((MutexDirect *)this)->_impl.release();
102 }
103 
104 ////////////////////////////////////////////////////////////////////
105 // Function: MutexDirect::debug_is_locked
106 // Access: Published
107 // Description: Returns true if the current thread has locked the
108 // Mutex, false otherwise. This method is only intended
109 // for use in debugging, hence the method name; in the
110 // MutexDirect case, it always returns true, since
111 // there's not a reliable way to determine this
112 // otherwise.
113 ////////////////////////////////////////////////////////////////////
114 INLINE bool MutexDirect::
116  return true;
117 }
118 
119 ////////////////////////////////////////////////////////////////////
120 // Function: MutexDirect::set_name
121 // Access: Public
122 // Description: The mutex name is only defined when compiling in
123 // DEBUG_THREADS mode.
124 ////////////////////////////////////////////////////////////////////
125 INLINE void MutexDirect::
126 set_name(const string &) {
127 }
128 
129 ////////////////////////////////////////////////////////////////////
130 // Function: MutexDirect::clear_name
131 // Access: Public
132 // Description: The mutex name is only defined when compiling in
133 // DEBUG_THREADS mode.
134 ////////////////////////////////////////////////////////////////////
135 INLINE void MutexDirect::
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: MutexDirect::has_name
141 // Access: Public
142 // Description: The mutex name is only defined when compiling in
143 // DEBUG_THREADS mode.
144 ////////////////////////////////////////////////////////////////////
145 INLINE bool MutexDirect::
146 has_name() const {
147  return false;
148 }
149 
150 ////////////////////////////////////////////////////////////////////
151 // Function: MutexDirect::get_name
152 // Access: Public
153 // Description: The mutex name is only defined when compiling in
154 // DEBUG_THREADS mode.
155 ////////////////////////////////////////////////////////////////////
156 INLINE string MutexDirect::
157 get_name() const {
158  return string();
159 }
void acquire() const
Grabs the mutex if it is available.
Definition: mutexDirect.I:70
bool debug_is_locked() const
Returns true if the current thread has locked the Mutex, false otherwise.
Definition: mutexDirect.I:115
void release() const
Releases the mutex.
Definition: mutexDirect.I:99
bool try_acquire() const
Returns immediately, with a true value indicating the mutex has been acquired, and false indicating i...
Definition: mutexDirect.I:83
void set_name(const string &name)
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition: mutexDirect.I:126
string get_name() const
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition: mutexDirect.I:157
void clear_name()
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition: mutexDirect.I:136
This class implements a standard mutex by making direct calls to the underlying implementation layer...
Definition: mutexDirect.h:32
bool has_name() const
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition: mutexDirect.I:146