15 #include "conditionVarFullDebug.h"
17 #include "config_pipeline.h"
31 ConditionVarFullDebug::
32 ConditionVarFullDebug(MutexDebug &mutex) :
34 _impl(*mutex.get_global_lock())
36 nassertv(!_mutex._allow_recursion);
44 ConditionVarFullDebug::
45 ~ConditionVarFullDebug() {
73 void ConditionVarFullDebug::
75 _mutex._global_lock->acquire();
79 if (!_mutex.do_debug_is_locked()) {
81 ostr << *current_thread <<
" attempted to wait on "
82 << *
this <<
" without holding " << _mutex;
83 nassert_raise(ostr.str());
84 _mutex._global_lock->release();
88 if (thread_cat->is_spam()) {
90 << *current_thread <<
" waiting on " << *
this <<
"\n";
93 nassertd(current_thread->_waiting_on_cvar == NULL &&
94 current_thread->_waiting_on_cvar_full == NULL) {
96 current_thread->_waiting_on_cvar_full =
this;
100 _mutex.do_acquire(current_thread);
102 nassertd(current_thread->_waiting_on_cvar_full ==
this) {
104 current_thread->_waiting_on_cvar_full = NULL;
106 if (thread_cat.is_spam()) {
108 << *current_thread <<
" awake on " << *
this <<
"\n";
111 _mutex._global_lock->release();
125 void ConditionVarFullDebug::
126 wait(
double timeout) {
127 _mutex._global_lock->acquire();
131 if (!_mutex.do_debug_is_locked()) {
133 ostr << *current_thread <<
" attempted to wait on "
134 << *
this <<
" without holding " << _mutex;
135 nassert_raise(ostr.str());
136 _mutex._global_lock->release();
140 if (thread_cat.is_spam()) {
142 << *current_thread <<
" waiting on " << *
this
143 <<
", with timeout " << timeout <<
"\n";
146 nassertd(current_thread->_waiting_on_cvar == NULL &&
147 current_thread->_waiting_on_cvar_full == NULL) {
149 current_thread->_waiting_on_cvar_full =
this;
153 _mutex.do_acquire(current_thread);
155 nassertd(current_thread->_waiting_on_cvar_full ==
this) {
157 current_thread->_waiting_on_cvar_full = NULL;
159 if (thread_cat.is_spam()) {
161 << *current_thread <<
" awake on " << *
this <<
"\n";
164 _mutex._global_lock->release();
184 void ConditionVarFullDebug::
186 _mutex._global_lock->acquire();
190 if (!_mutex.do_debug_is_locked()) {
192 ostr << *current_thread <<
" attempted to notify "
193 << *
this <<
" without holding " << _mutex;
194 nassert_raise(ostr.str());
195 _mutex._global_lock->release();
199 if (thread_cat->is_spam()) {
201 << *current_thread <<
" notifying " << *
this <<
"\n";
205 _mutex._global_lock->release();
222 void ConditionVarFullDebug::
224 _mutex._global_lock->acquire();
228 if (!_mutex.do_debug_is_locked()) {
230 ostr << *current_thread <<
" attempted to notify "
231 << *
this <<
" without holding " << _mutex;
232 nassert_raise(ostr.str());
233 _mutex._global_lock->release();
237 if (thread_cat->is_spam()) {
239 << *current_thread <<
" notifying all " << *
this <<
"\n";
243 _mutex._global_lock->release();
252 void ConditionVarFullDebug::
253 output(ostream &out)
const {
254 out <<
"ConditionVarFull " << (
void *)
this <<
" on " << _mutex;
257 #endif // DEBUG_THREADS
static Thread * get_current_thread()
Returns a pointer to the currently-executing Thread object.
A thread; that is, a lightweight process.