00001 #include "condition.h" 00002 00003 namespace n2nc { 00004 namespace sync { 00005 00006 Condition::Condition(Mutex &mutex) : m_mutex(mutex) { 00007 00008 } 00009 00010 bool n2nc::sync::Condition::wait(){ 00012 if (::pthread_mutex_trylock(& this->m_mutex.m_mutex) != EBUSY){ 00014 ::pthread_mutex_unlock(& this->m_mutex.m_mutex); 00015 std::cerr << "Condition would wait outside a lock" << std::endl ; 00016 exit(1); 00017 return false ; 00018 }else{ 00019 return !::pthread_cond_wait(&this->m_cond,&this->m_mutex.m_mutex); 00020 } 00021 00022 } 00023 00024 bool n2nc::sync::Condition::signal(){ 00025 return !::pthread_cond_signal(&this->m_cond); 00026 } 00027 00028 Condition::~Condition(){ 00029 } 00030 00031 00032 } 00033 } 00034 00035