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

#include <thread.h>

Public Member Functions

 Semaphore ()
 
 Semaphore (unsigned count0)
 
void wait ()
 
void post ()
 

Private Attributes

Lock lock
 
ConditionVariable cond
 
unsigned count
 
unsigned waiting
 

Detailed Description

Definition at line 111 of file thread.h.

Constructor & Destructor Documentation

◆ Semaphore() [1/2]

Semaphore::Semaphore ( )
inline

Definition at line 118 of file thread.h.

118 : lock(), cond(&lock), count(0), waiting(0) {
119 }
ConditionVariable cond
Definition: thread.h:114
Lock lock
Definition: thread.h:113
unsigned waiting
Definition: thread.h:116
unsigned count
Definition: thread.h:115

◆ Semaphore() [2/2]

Semaphore::Semaphore ( unsigned  count0)
inline

Definition at line 120 of file thread.h.

120 : lock(), cond(&lock), count(count0), waiting(0) {
121 }

Member Function Documentation

◆ post()

void Semaphore::post ( )

Definition at line 33 of file thread.cc.

33 {
34 lock.lock();
35 if (count++ == 0 && waiting)
36 cond.signal();
37 lock.unlock();
38}
void signal()
Definition: thread.h:97
void lock()
Definition: thread.h:46
void unlock()
Definition: thread.h:57

◆ wait()

void Semaphore::wait ( )

Definition at line 23 of file thread.cc.

23 {
24 lock.lock();
25 waiting++;
26 while (count == 0)
27 cond.wait();
28 waiting--;
29 count--;
30 lock.unlock();
31}
void wait()
Definition: thread.h:88

Field Documentation

◆ cond

ConditionVariable Semaphore::cond
private

Definition at line 114 of file thread.h.

◆ count

unsigned Semaphore::count
private

Definition at line 115 of file thread.h.

◆ lock

Lock Semaphore::lock
private

Definition at line 113 of file thread.h.

◆ waiting

unsigned Semaphore::waiting
private

Definition at line 116 of file thread.h.


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