21 using std::ostringstream;
29 ConditionVarFullDebug::
30 ConditionVarFullDebug(MutexDebug &mutex) :
32 _impl(*mutex.get_global_lock())
34 nassertv(!_mutex._allow_recursion);
40 ConditionVarFullDebug::
41 ~ConditionVarFullDebug() {
61 void ConditionVarFullDebug::
63 _mutex._global_lock->lock();
67 if (!_mutex.do_debug_is_locked()) {
69 ostr << *current_thread <<
" attempted to wait on " 70 << *
this <<
" without holding " << _mutex;
71 nassert_raise(ostr.str());
72 _mutex._global_lock->unlock();
76 if (thread_cat->is_spam()) {
78 << *current_thread <<
" waiting on " << *
this <<
"\n";
81 nassertd(current_thread->_waiting_on_cvar ==
nullptr &&
82 current_thread->_waiting_on_cvar_full ==
nullptr) {
84 current_thread->_waiting_on_cvar_full =
this;
88 _mutex.do_lock(current_thread);
90 nassertd(current_thread->_waiting_on_cvar_full ==
this) {
92 current_thread->_waiting_on_cvar_full =
nullptr;
94 if (thread_cat.is_spam()) {
96 << *current_thread <<
" awake on " << *
this <<
"\n";
99 _mutex._global_lock->unlock();
110 void ConditionVarFullDebug::
111 wait(
double timeout) {
112 _mutex._global_lock->lock();
116 if (!_mutex.do_debug_is_locked()) {
118 ostr << *current_thread <<
" attempted to wait on " 119 << *
this <<
" without holding " << _mutex;
120 nassert_raise(ostr.str());
121 _mutex._global_lock->unlock();
125 if (thread_cat.is_spam()) {
127 << *current_thread <<
" waiting on " << *
this 128 <<
", with timeout " << timeout <<
"\n";
131 nassertd(current_thread->_waiting_on_cvar ==
nullptr &&
132 current_thread->_waiting_on_cvar_full ==
nullptr) {
134 current_thread->_waiting_on_cvar_full =
this;
138 _mutex.do_lock(current_thread);
140 nassertd(current_thread->_waiting_on_cvar_full ==
this) {
142 current_thread->_waiting_on_cvar_full =
nullptr;
144 if (thread_cat.is_spam()) {
146 << *current_thread <<
" awake on " << *
this <<
"\n";
149 _mutex._global_lock->unlock();
164 void ConditionVarFullDebug::
166 _mutex._global_lock->lock();
170 if (!_mutex.do_debug_is_locked()) {
172 ostr << *current_thread <<
" attempted to notify " 173 << *
this <<
" without holding " << _mutex;
174 nassert_raise(ostr.str());
175 _mutex._global_lock->unlock();
179 if (thread_cat->is_spam()) {
181 << *current_thread <<
" notifying " << *
this <<
"\n";
185 _mutex._global_lock->unlock();
197 void ConditionVarFullDebug::
199 _mutex._global_lock->lock();
203 if (!_mutex.do_debug_is_locked()) {
205 ostr << *current_thread <<
" attempted to notify " 206 << *
this <<
" without holding " << _mutex;
207 nassert_raise(ostr.str());
208 _mutex._global_lock->unlock();
212 if (thread_cat->is_spam()) {
214 << *current_thread <<
" notifying all " << *
this <<
"\n";
218 _mutex._global_lock->unlock();
225 void ConditionVarFullDebug::
226 output(ostream &out)
const {
227 out <<
"ConditionVarFull " << (
void *)
this <<
" on " << _mutex;
230 #endif // DEBUG_THREADS PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_current_thread
Returns a pointer to the currently-executing Thread object.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A thread; that is, a lightweight process.