Belle II Software development
MCond Class Reference

Public Member Functions

 MCond (const MCond &)
 
 MCond (void *)
 
bool init (void *)
 
bool init ()
 
bool set (void *)
 
bool signal ()
 
bool broadcast ()
 
bool wait (MMutex &mutex)
 
bool wait (MMutex &mutex, const unsigned int sec, const unsigned int msec=0)
 
bool destroy ()
 
const MCondoperator= (const MCond &)
 

Static Public Member Functions

static size_t size ()
 

Private Attributes

pthread_cond_t * m_cond
 

Detailed Description

Definition at line 21 of file MCond.h.

Constructor & Destructor Documentation

◆ MCond() [1/3]

MCond ( )

Definition at line 14 of file MCond.cc.

14{}

◆ MCond() [2/3]

MCond ( const MCond cond)

Definition at line 16 of file MCond.cc.

17{
18 *this = cond;
19}

◆ MCond() [3/3]

MCond ( void *  addr)

Definition at line 21 of file MCond.cc.

22{
23 set((pthread_cond_t*)addr);
24}

◆ ~MCond()

~MCond ( )

Definition at line 26 of file MCond.cc.

26{}

Member Function Documentation

◆ broadcast()

bool broadcast ( )

Definition at line 63 of file MCond.cc.

64{
65 if (pthread_cond_broadcast(m_cond) == 0) return true;
66 else return false;
67}

◆ destroy()

bool destroy ( )

Definition at line 51 of file MCond.cc.

52{
53 pthread_cond_destroy(m_cond);
54 return true;
55}

◆ init() [1/2]

bool init ( )

Definition at line 35 of file MCond.cc.

36{
37 pthread_condattr_t attr;
38 pthread_condattr_init(&attr);
39 pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
40 pthread_cond_init(m_cond, &attr);
41 pthread_condattr_destroy(&attr);
42 return true;
43}

◆ init() [2/2]

bool init ( void *  addr)

Definition at line 28 of file MCond.cc.

29{
30 set(addr);
31 init();
32 return true;
33}

◆ operator=()

const MCond & operator= ( const MCond cond)

Definition at line 92 of file MCond.cc.

93{
94 m_cond = cond.m_cond;
95 return *this;
96}

◆ set()

bool set ( void *  addr)

Definition at line 45 of file MCond.cc.

46{
47 m_cond = (pthread_cond_t*)addr;
48 return true;
49}

◆ signal()

bool signal ( )

Definition at line 57 of file MCond.cc.

58{
59 if (pthread_cond_signal(m_cond) == 0) return true;
60 else return false;
61}

◆ size()

static size_t size ( )
inlinestatic

Definition at line 24 of file MCond.h.

24{ return sizeof(pthread_cond_t); }

◆ wait() [1/2]

bool wait ( MMutex mutex)

Definition at line 69 of file MCond.cc.

70{
71 if (pthread_cond_wait(m_cond, cond.m_mu) != 0) {
72 return false;
73 }
74 return true;
75}

◆ wait() [2/2]

bool wait ( MMutex mutex,
const unsigned int  sec,
const unsigned int  msec = 0 
)

Definition at line 77 of file MCond.cc.

79{
80 struct timeval now;
81 struct timespec timeout;
82
83 gettimeofday(&now, NULL);
84 timeout.tv_sec = now.tv_sec + sec;
85 timeout.tv_nsec = now.tv_usec * 1000 + msec;
86 if (pthread_cond_timedwait(m_cond, mutex.m_mu, &timeout) != 0) {
87 return false;
88 }
89 return true;
90}

Member Data Documentation

◆ m_cond

pthread_cond_t* m_cond
private

Definition at line 50 of file MCond.h.


The documentation for this class was generated from the following files: