My Project
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | Friends
ConditionVariable Class Reference

#include <thread.h>

Public Member Functions

 ConditionVariable (Lock *lock_init)
 
 ~ConditionVariable ()
 
void wait ()
 
void signal ()
 
void broadcast ()
 

Private Member Functions

 ConditionVariable ()
 

Private Attributes

pthread_cond_t condition
 
Locklock
 
int waiting
 

Friends

class Lock
 
class Semaphore
 

Detailed Description

Definition at line 73 of file thread.h.

Constructor & Destructor Documentation

◆ ConditionVariable() [1/2]

ConditionVariable::ConditionVariable ( )
inlineprivate

Definition at line 80 of file thread.h.

80{ }

◆ ConditionVariable() [2/2]

ConditionVariable::ConditionVariable ( Lock lock_init)
inline

Definition at line 82 of file thread.h.

82 : waiting(0), lock(lock_init) {
83 pthread_cond_init(&condition, NULL);
84 }
pthread_cond_t condition
Definition: thread.h:76
Lock * lock
Definition: thread.h:77
#define NULL
Definition: omList.c:12

◆ ~ConditionVariable()

ConditionVariable::~ConditionVariable ( )
inline

Definition at line 85 of file thread.h.

85 {
86 pthread_cond_destroy(&condition);
87 }

Member Function Documentation

◆ broadcast()

void ConditionVariable::broadcast ( )
inline

Definition at line 103 of file thread.h.

103 {
104 if (!lock->is_locked())
105 ThreadError("signaled condition without locked mutex");
106 if (waiting)
107 pthread_cond_broadcast(&condition);
108 }
bool is_locked()
Definition: thread.h:68
void ThreadError(const char *message)
Definition: thread.cc:18

◆ signal()

void ConditionVariable::signal ( )
inline

Definition at line 97 of file thread.h.

97 {
98 if (!lock->is_locked())
99 ThreadError("signaled condition without locked mutex");
100 if (waiting)
101 pthread_cond_signal(&condition);
102 }

◆ wait()

void ConditionVariable::wait ( )
inline

Definition at line 88 of file thread.h.

88 {
89 if (!lock->is_locked())
90 ThreadError("waited on condition without locked mutex");
91 waiting++;
92 int l = lock->break_lock();
93 pthread_cond_wait(&condition, &lock->mutex);
94 waiting--;
96 }
int l
Definition: cfEzgcd.cc:100
int break_lock()
Definition: thread.h:28
pthread_mutex_t mutex
Definition: thread.h:19
void resume_lock(int l)
Definition: thread.h:24

Friends And Related Function Documentation

◆ Lock

friend class Lock
friend

Definition at line 74 of file thread.h.

◆ Semaphore

friend class Semaphore
friend

Definition at line 79 of file thread.h.

Field Documentation

◆ condition

pthread_cond_t ConditionVariable::condition
private

Definition at line 76 of file thread.h.

◆ lock

Lock* ConditionVariable::lock
private

Definition at line 77 of file thread.h.

◆ waiting

int ConditionVariable::waiting
private

Definition at line 78 of file thread.h.


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