comparison thread/Thread.cpp @ 69:6afa0e011f74

* Fix some locking problems
author cannam
date Thu, 21 May 2009 16:39:35 +0000
parents b63f1ccbc9b6
children c10ac368f5cf
comparison
equal deleted inserted replaced
68:09aba2ccd94a 69:6afa0e011f74
205 } 205 }
206 206
207 void 207 void
208 Condition::lock() 208 Condition::lock()
209 { 209 {
210 if (m_locked) {
211 #ifdef DEBUG_CONDITION
212 cerr << "CONDITION DEBUG: " << (void *)GetCurrentThreadId() << ": Already locked " << &m_condition << " \"" << m_name << "\"" << endl;
213 #endif
214 return;
215 }
216 #ifdef DEBUG_CONDITION 210 #ifdef DEBUG_CONDITION
217 cerr << "CONDITION DEBUG: " << (void *)GetCurrentThreadId() << ": Want to lock " << &m_condition << " \"" << m_name << "\"" << endl; 211 cerr << "CONDITION DEBUG: " << (void *)GetCurrentThreadId() << ": Want to lock " << &m_condition << " \"" << m_name << "\"" << endl;
218 #endif 212 #endif
219 WaitForSingleObject(m_mutex, INFINITE); 213 WaitForSingleObject(m_mutex, INFINITE);
220 m_locked = true; 214 m_locked = true;
466 } 460 }
467 461
468 void 462 void
469 Condition::lock() 463 Condition::lock()
470 { 464 {
471 if (m_locked) {
472 #ifdef DEBUG_CONDITION
473 cerr << "CONDITION DEBUG: " << (void *)pthread_self() << ": Already locked " << &m_condition << " \"" << m_name << "\"" << endl;
474 #endif
475 return;
476 }
477 #ifdef DEBUG_CONDITION 465 #ifdef DEBUG_CONDITION
478 cerr << "CONDITION DEBUG: " << (void *)pthread_self() << ": Want to lock " << &m_condition << " \"" << m_name << "\"" << endl; 466 cerr << "CONDITION DEBUG: " << (void *)pthread_self() << ": Want to lock " << &m_condition << " \"" << m_name << "\"" << endl;
479 #endif 467 #endif
480 pthread_mutex_lock(&m_mutex); 468 pthread_mutex_lock(&m_mutex);
481 m_locked = true; 469 m_locked = true;
532 } 520 }
533 521
534 #ifdef DEBUG_CONDITION 522 #ifdef DEBUG_CONDITION
535 cerr << "CONDITION DEBUG: " << (void *)pthread_self() << ": Wait done on " << &m_condition << " \"" << m_name << "\"" << endl; 523 cerr << "CONDITION DEBUG: " << (void *)pthread_self() << ": Wait done on " << &m_condition << " \"" << m_name << "\"" << endl;
536 #endif 524 #endif
525
526 m_locked = true;
537 } 527 }
538 528
539 void 529 void
540 Condition::signal() 530 Condition::signal()
541 { 531 {