1 #include "daq/slc/system/MCond.h"
9 MCond::MCond(
const MCond& cond)
14 MCond::MCond(
void* addr)
16 set((pthread_cond_t*)addr);
21 bool MCond::init(
void* addr)
30 pthread_condattr_t attr;
31 pthread_condattr_init(&attr);
32 pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
33 pthread_cond_init(m_cond, &attr);
34 pthread_condattr_destroy(&attr);
38 bool MCond::set(
void* addr)
40 m_cond = (pthread_cond_t*)addr;
46 pthread_cond_destroy(m_cond);
52 if (pthread_cond_signal(m_cond) == 0)
return true;
56 bool MCond::broadcast()
58 if (pthread_cond_broadcast(m_cond) == 0)
return true;
62 bool MCond::wait(
MMutex& cond)
64 if (pthread_cond_wait(m_cond, cond.m_mu) != 0) {
70 bool MCond::wait(
MMutex& mutex,
const unsigned int sec,
71 const unsigned int msec)
74 struct timespec timeout;
76 gettimeofday(&now, NULL);
77 timeout.tv_sec = now.tv_sec + sec;
78 timeout.tv_nsec = now.tv_usec * 1000 + msec;
79 if (pthread_cond_timedwait(m_cond, mutex.m_mu, &timeout) != 0) {
85 const MCond& MCond::operator=(
const MCond& cond)