Belle II Software development
Cond Class Reference

Public Member Functions

 Cond (const Cond &cond)
 
bool init ()
 
bool signal ()
 
bool broadcast ()
 
bool wait (Mutex &mutex)
 
bool wait (Mutex &mutex, const unsigned int sec, const unsigned int msec=0)
 
bool destroy ()
 

Private Attributes

pthread_cond_t m_cond_t
 

Detailed Description

Definition at line 19 of file Cond.h.

Constructor & Destructor Documentation

◆ Cond() [1/2]

Cond ( )

Definition at line 15 of file Cond.cc.

16{
17 init();
18}

◆ Cond() [2/2]

Cond ( const Cond & cond)

Definition at line 20 of file Cond.cc.

20 : m_cond_t(cond.m_cond_t)
21{
22}

◆ ~Cond()

~Cond ( )
inline

Definition at line 24 of file Cond.h.

24{};

Member Function Documentation

◆ broadcast()

bool broadcast ( )

Definition at line 43 of file Cond.cc.

44{
45 if (pthread_cond_broadcast(&m_cond_t) == 0) return true;
46 else return false;
47}

◆ destroy()

bool destroy ( )

Definition at line 71 of file Cond.cc.

72{
73 if (pthread_cond_destroy(&m_cond_t) == 0) return true;
74 else return false;
75}

◆ init()

bool init ( )

Definition at line 24 of file Cond.cc.

25{
26 pthread_condattr_t mattr;
27 pthread_condattr_init(&mattr);
28 pthread_condattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
29 if (pthread_cond_init(&m_cond_t, &mattr) != 0) {
30 return false;
31 }
32 pthread_condattr_destroy(&mattr);
33
34 return true;
35}

◆ signal()

bool signal ( )

Definition at line 37 of file Cond.cc.

38{
39 if (pthread_cond_signal(&m_cond_t) == 0) return true;
40 else return false;
41}

◆ wait() [1/2]

bool wait ( Mutex & mutex)

Definition at line 49 of file Cond.cc.

50{
51 if (pthread_cond_wait(&m_cond_t, &mutex.m_mu) != 0) {
52 return false;
53 }
54 return true;
55}

◆ wait() [2/2]

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

Definition at line 57 of file Cond.cc.

58{
59 struct timeval now;
60 struct timespec timeout;
61
62 gettimeofday(&now, NULL);
63 timeout.tv_sec = now.tv_sec + sec;
64 timeout.tv_nsec = now.tv_usec * 1000 + msec;
65 if (pthread_cond_timedwait(&m_cond_t, &mutex.m_mu, &timeout) != 0) { // check on stat code
66 return false;
67 }
68 return true;
69}

Member Data Documentation

◆ m_cond_t

pthread_cond_t m_cond_t
private

Definition at line 36 of file Cond.h.


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