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.

21{
22 m_cond_t = cond.m_cond_t;
23}

◆ ~Cond()

~Cond ( )
inline

Definition at line 24 of file Cond.h.

24{};

Member Function Documentation

◆ broadcast()

bool broadcast ( )

Definition at line 44 of file Cond.cc.

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

◆ destroy()

bool destroy ( )

Definition at line 72 of file Cond.cc.

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

◆ init()

bool init ( )

Definition at line 25 of file Cond.cc.

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

◆ signal()

bool signal ( )

Definition at line 38 of file Cond.cc.

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

◆ wait() [1/2]

bool wait ( Mutex mutex)

Definition at line 50 of file Cond.cc.

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

◆ wait() [2/2]

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

Definition at line 58 of file Cond.cc.

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

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: