00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "conditionVarFullDebug.h"
00016 #include "thread.h"
00017 #include "config_pipeline.h"
00018
00019 #ifdef DEBUG_THREADS
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 ConditionVarFullDebug::
00032 ConditionVarFullDebug(MutexDebug &mutex) :
00033 _mutex(mutex),
00034 _impl(*mutex.get_global_lock())
00035 {
00036 nassertv(!_mutex._allow_recursion);
00037 }
00038
00039
00040
00041
00042
00043
00044 ConditionVarFullDebug::
00045 ~ConditionVarFullDebug() {
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 void ConditionVarFullDebug::
00074 wait() {
00075 _mutex._global_lock->acquire();
00076
00077 Thread *current_thread = Thread::get_current_thread();
00078
00079 if (!_mutex.do_debug_is_locked()) {
00080 ostringstream ostr;
00081 ostr << *current_thread << " attempted to wait on "
00082 << *this << " without holding " << _mutex;
00083 nassert_raise(ostr.str());
00084 _mutex._global_lock->release();
00085 return;
00086 }
00087
00088 if (thread_cat->is_spam()) {
00089 thread_cat.spam()
00090 << *current_thread << " waiting on " << *this << "\n";
00091 }
00092
00093 nassertd(current_thread->_waiting_on_cvar == NULL &&
00094 current_thread->_waiting_on_cvar_full == NULL) {
00095 }
00096 current_thread->_waiting_on_cvar_full = this;
00097
00098 _mutex.do_release();
00099 _impl.wait();
00100 _mutex.do_acquire(current_thread);
00101
00102 nassertd(current_thread->_waiting_on_cvar_full == this) {
00103 }
00104 current_thread->_waiting_on_cvar_full = NULL;
00105
00106 if (thread_cat.is_spam()) {
00107 thread_cat.spam()
00108 << *current_thread << " awake on " << *this << "\n";
00109 }
00110
00111 _mutex._global_lock->release();
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 void ConditionVarFullDebug::
00126 wait(double timeout) {
00127 _mutex._global_lock->acquire();
00128
00129 Thread *current_thread = Thread::get_current_thread();
00130
00131 if (!_mutex.do_debug_is_locked()) {
00132 ostringstream ostr;
00133 ostr << *current_thread << " attempted to wait on "
00134 << *this << " without holding " << _mutex;
00135 nassert_raise(ostr.str());
00136 _mutex._global_lock->release();
00137 return;
00138 }
00139
00140 if (thread_cat.is_spam()) {
00141 thread_cat.spam()
00142 << *current_thread << " waiting on " << *this
00143 << ", with timeout " << timeout << "\n";
00144 }
00145
00146 nassertd(current_thread->_waiting_on_cvar == NULL &&
00147 current_thread->_waiting_on_cvar_full == NULL) {
00148 }
00149 current_thread->_waiting_on_cvar_full = this;
00150
00151 _mutex.do_release();
00152 _impl.wait(timeout);
00153 _mutex.do_acquire(current_thread);
00154
00155 nassertd(current_thread->_waiting_on_cvar_full == this) {
00156 }
00157 current_thread->_waiting_on_cvar_full = NULL;
00158
00159 if (thread_cat.is_spam()) {
00160 thread_cat.spam()
00161 << *current_thread << " awake on " << *this << "\n";
00162 }
00163
00164 _mutex._global_lock->release();
00165 }
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 void ConditionVarFullDebug::
00185 notify() {
00186 _mutex._global_lock->acquire();
00187
00188 Thread *current_thread = Thread::get_current_thread();
00189
00190 if (!_mutex.do_debug_is_locked()) {
00191 ostringstream ostr;
00192 ostr << *current_thread << " attempted to notify "
00193 << *this << " without holding " << _mutex;
00194 nassert_raise(ostr.str());
00195 _mutex._global_lock->release();
00196 return;
00197 }
00198
00199 if (thread_cat->is_spam()) {
00200 thread_cat.spam()
00201 << *current_thread << " notifying " << *this << "\n";
00202 }
00203
00204 _impl.notify();
00205 _mutex._global_lock->release();
00206 }
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 void ConditionVarFullDebug::
00223 notify_all() {
00224 _mutex._global_lock->acquire();
00225
00226 Thread *current_thread = Thread::get_current_thread();
00227
00228 if (!_mutex.do_debug_is_locked()) {
00229 ostringstream ostr;
00230 ostr << *current_thread << " attempted to notify "
00231 << *this << " without holding " << _mutex;
00232 nassert_raise(ostr.str());
00233 _mutex._global_lock->release();
00234 return;
00235 }
00236
00237 if (thread_cat->is_spam()) {
00238 thread_cat.spam()
00239 << *current_thread << " notifying all " << *this << "\n";
00240 }
00241
00242 _impl.notify_all();
00243 _mutex._global_lock->release();
00244 }
00245
00246
00247
00248
00249
00250
00251
00252 void ConditionVarFullDebug::
00253 output(ostream &out) const {
00254 out << "ConditionVarFull " << (void *)this << " on " << _mutex;
00255 }
00256
00257 #endif // DEBUG_THREADS