00001 // Copyright CERN 2012 - Developed in collaboration with GSI 00002 00003 #include <fesa-core/Utilities/ConditionalVariable.h> 00004 00005 #include <fesa-core/Utilities/Mutex.h> 00006 #include <fesa-core/Exception/FesaException.h> 00007 00008 00009 // TODO use if-expressions and throw errors on failure 00010 00011 namespace fesa 00012 { 00013 00014 ConditionalVariable::ConditionalVariable() 00015 { 00016 if (pthread_cond_init(&condition_, NULL) != 0) 00017 throw FesaException(__FILE__, __LINE__, FesaErrorCreatingConditionalVariable.c_str()); 00018 00019 } 00020 00021 ConditionalVariable::~ConditionalVariable() 00022 { 00023 pthread_cond_destroy(&condition_); 00024 00025 } 00026 00032 void ConditionalVariable::signal() 00033 { 00034 if (pthread_cond_signal(&condition_) != 0) 00035 throw FesaException(__FILE__, __LINE__, FesaErrorSignalingConditionalVariable.c_str()); 00036 } 00037 00044 void ConditionalVariable::wait(Mutex& mutex) 00045 { 00046 int32_t err = pthread_cond_wait(&condition_, mutex.lock_); 00047 if (err != 0) 00048 throw FesaException(__FILE__, __LINE__, FesaErrorWaitingConditionalVariable.c_str()); 00049 } 00050 00051 } // fesa