Panda3D
conditionVarFullDirect.I
1 // Filename: conditionVarFullDirect.I
2 // Created by: drose (28Aug06)
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: ConditionVarFullDirect::Constructor
18 // Access: Public
19 // Description: You must pass in a Mutex to the condition variable
20 // constructor. This mutex may be shared by other
21 // condition variables, if desired. It is the caller's
22 // responsibility to ensure the Mutex object does not
23 // destruct during the lifetime of the condition
24 // variable.
25 ////////////////////////////////////////////////////////////////////
28  _mutex(mutex),
29  _impl(mutex._impl)
30 {
31 }
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function: ConditionVarFullDirect::Destructor
35 // Access: Public
36 // Description:
37 ////////////////////////////////////////////////////////////////////
38 INLINE ConditionVarFullDirect::
39 ~ConditionVarFullDirect() {
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: ConditionVarFullDirect::Copy Constructor
44 // Access: Private
45 // Description: Do not attempt to copy condition variables.
46 ////////////////////////////////////////////////////////////////////
49  _mutex(copy._mutex),
50  _impl(_mutex._impl)
51 {
52  nassertv(false);
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: ConditionVarFullDirect::Copy Assignment Operator
57 // Access: Private
58 // Description: Do not attempt to copy condition variables.
59 ////////////////////////////////////////////////////////////////////
60 INLINE void ConditionVarFullDirect::
61 operator = (const ConditionVarFullDirect &copy) {
62  nassertv(false);
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: ConditionVarFullDirect::get_mutex
67 // Access: Published
68 // Description: Returns the mutex associated with this condition
69 // variable.
70 ////////////////////////////////////////////////////////////////////
72 get_mutex() const {
73  return _mutex;
74 }
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function: ConditionVarFullDirect::wait
78 // Access: Published
79 // Description: Waits on the condition. The caller must already be
80 // holding the lock associated with the condition
81 // variable before calling this function.
82 //
83 // wait() will release the lock, then go to sleep until
84 // some other thread calls notify() on this condition
85 // variable. At that time at least one thread waiting
86 // on the same ConditionVarFullDirect will grab the lock again,
87 // and then return from wait().
88 //
89 // It is possible that wait() will return even if no one
90 // has called notify(). It is the responsibility of the
91 // calling process to verify the condition on return
92 // from wait, and possibly loop back to wait again if
93 // necessary.
94 //
95 // Note the semantics of a condition variable: the mutex
96 // must be held before wait() is called, and it will
97 // still be held when wait() returns. However, it will
98 // be temporarily released during the wait() call
99 // itself.
100 ////////////////////////////////////////////////////////////////////
101 INLINE void ConditionVarFullDirect::
102 wait() {
103  TAU_PROFILE("ConditionVarFullDirect::wait()", " ", TAU_USER);
104  _impl.wait();
105 }
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: ConditionVarFullDirect::wait
109 // Access: Published
110 // Description: Waits on the condition, with a timeout. The function
111 // will return when the condition variable is notified,
112 // or the timeout occurs. There is no way to directly
113 // tell which happened, and it is possible that neither
114 // in fact happened (spurious wakeups are possible).
115 //
116 // See wait() with no parameters for more.
117 ////////////////////////////////////////////////////////////////////
119 wait(double timeout) {
120  TAU_PROFILE("ConditionVarFullDirect::wait(double)", " ", TAU_USER);
121  _impl.wait(timeout);
122 }
123 
124 ////////////////////////////////////////////////////////////////////
125 // Function: ConditionVarFullDirect::notify
126 // Access: Published
127 // Description: Informs one of the other threads who are currently
128 // blocked on wait() that the relevant condition has
129 // changed. If multiple threads are currently waiting,
130 // at least one of them will be woken up, although there
131 // is no way to predict which one. It is possible that
132 // more than one thread will be woken up.
133 //
134 // The caller must be holding the mutex associated with
135 // the condition variable before making this call, which
136 // will not release the mutex.
137 //
138 // If no threads are waiting, this is a no-op: the
139 // notify is lost.
140 ////////////////////////////////////////////////////////////////////
141 INLINE void ConditionVarFullDirect::
143  TAU_PROFILE("ConditionVarFullDirect::notify()", " ", TAU_USER);
144  _impl.notify();
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: ConditionVarFullDirect::notify_all
149 // Access: Published
150 // Description: Informs all of the other threads who are currently
151 // blocked on wait() that the relevant condition has
152 // changed.
153 //
154 // The caller must be holding the mutex associated with
155 // the condition variable before making this call, which
156 // will not release the mutex.
157 //
158 // If no threads are waiting, this is a no-op: the
159 // notify event is lost.
160 ////////////////////////////////////////////////////////////////////
161 INLINE void ConditionVarFullDirect::
163  TAU_PROFILE("ConditionVarFullDirect::notify()", " ", TAU_USER);
164  _impl.notify_all();
165 }
void notify()
Informs one of the other threads who are currently blocked on wait() that the relevant condition has ...
void wait()
Waits on the condition.
void notify_all()
Informs all of the other threads who are currently blocked on wait() that the relevant condition has ...
MutexDirect & get_mutex() const
Returns the mutex associated with this condition variable.
A condition variable, usually used to communicate information about changing state to a thread that i...
ConditionVarFullDirect(MutexDirect &mutex)
You must pass in a Mutex to the condition variable constructor.
This class implements a standard mutex by making direct calls to the underlying implementation layer...
Definition: mutexDirect.h:32