Panda3D
 All Classes Functions Variables Enumerations
conditionVarDirect.I
1 // Filename: conditionVarDirect.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: ConditionVarDirect::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: ConditionVarDirect::Destructor
35 // Access: Public
36 // Description:
37 ////////////////////////////////////////////////////////////////////
38 INLINE ConditionVarDirect::
39 ~ConditionVarDirect() {
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: ConditionVarDirect::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: ConditionVarDirect::Copy Assignment Operator
57 // Access: Private
58 // Description: Do not attempt to copy condition variables.
59 ////////////////////////////////////////////////////////////////////
60 INLINE void ConditionVarDirect::
61 operator = (const ConditionVarDirect &copy) {
62  nassertv(false);
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: ConditionVarDirect::get_mutex
67 // Access: Public
68 // Description: Returns the mutex associated with this condition
69 // variable.
70 ////////////////////////////////////////////////////////////////////
72 get_mutex() const {
73  return _mutex;
74 }
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function: ConditionVarDirect::wait
78 // Access: Public
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 ConditionVarDirect 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 ConditionVarDirect::
102 wait() {
103  TAU_PROFILE("ConditionVarDirect::wait()", " ", TAU_USER);
104  _impl.wait();
105 }
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: ConditionVarDirect::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("ConditionVarDirect::wait(double)", " ", TAU_USER);
121  _impl.wait(timeout);
122 }
123 
124 ////////////////////////////////////////////////////////////////////
125 // Function: ConditionVarDirect::notify
126 // Access: Public
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 event is lost.
140 ////////////////////////////////////////////////////////////////////
141 INLINE void ConditionVarDirect::
143  TAU_PROFILE("ConditionVarDirect::notify()", " ", TAU_USER);
144  _impl.notify();
145 }
ConditionVarDirect(MutexDirect &mutex)
You must pass in a Mutex to the condition variable constructor.
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...
void wait()
Waits on the condition.
void notify()
Informs one of the other threads who are currently blocked on wait() that the relevant condition has ...
This class implements a standard mutex by making direct calls to the underlying implementation layer...
Definition: mutexDirect.h:32