21 using std::ostringstream;
30 ConditionVarDebug(MutexDebug &mutex) :
32 _impl(*mutex.get_global_lock())
34 nassertv(!_mutex._allow_recursion);
41 ~ConditionVarDebug() {
61 void ConditionVarDebug::
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 =
this;
88 _mutex.do_lock(current_thread);
90 nassertd(current_thread->_waiting_on_cvar ==
this) {
92 current_thread->_waiting_on_cvar =
nullptr;
94 if (thread_cat.is_spam()) {
96 << *current_thread <<
" awake on " << *
this <<
"\n";
99 _mutex._global_lock->unlock();
110 void ConditionVarDebug::
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 =
this;
138 _mutex.do_lock(current_thread);
140 nassertd(current_thread->_waiting_on_cvar ==
this) {
142 current_thread->_waiting_on_cvar =
nullptr;
144 if (thread_cat.is_spam()) {
146 << *current_thread <<
" awake on " << *
this <<
"\n";
149 _mutex._global_lock->unlock();
164 void ConditionVarDebug::
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();
192 void ConditionVarDebug::
193 output(ostream &out)
const {
194 out <<
"ConditionVar " << (
void *)
this <<
" on " << _mutex;
197 #endif // DEBUG_THREADS PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
A thread; that is, a lightweight process.