1 #include "daq/slc/system/Cond.h"
13 Cond::Cond(
const Cond& cond)
15 m_cond_t = cond.m_cond_t;
20 pthread_condattr_t mattr;
21 pthread_condattr_init(&mattr);
22 pthread_condattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
23 if (pthread_cond_init(&m_cond_t, &mattr) != 0) {
26 pthread_condattr_destroy(&mattr);
33 if (pthread_cond_signal(&m_cond_t) == 0)
return true;
37 bool Cond::broadcast()
39 if (pthread_cond_broadcast(&m_cond_t) == 0)
return true;
43 bool Cond::wait(
Mutex& mutex)
45 if (pthread_cond_wait(&m_cond_t, &mutex.m_mu) != 0) {
51 bool Cond::wait(
Mutex& mutex,
const unsigned int sec,
const unsigned int msec)
54 struct timespec timeout;
56 gettimeofday(&now, NULL);
57 timeout.tv_sec = now.tv_sec + sec;
58 timeout.tv_nsec = now.tv_usec * 1000 + msec;
60 if ((stat = pthread_cond_timedwait(&m_cond_t, &mutex.m_mu, &timeout)) != 0) {
68 if (pthread_cond_destroy(&m_cond_t) == 0)
return true;