Loading...
Searching...
No Matches
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.

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

## Semaphore() [2/2]

Semaphore::Semaphore | ( | unsigned | count0 | ) |

inline

Definition at line 120 of file thread.h.

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

## Member Function Documentation

## post()

void Semaphore::post | ( |  | ) |

Definition at line 33 of file thread.cc.

{
lock.lock();
if (count++ == 0 && waiting)
cond.signal();
lock.unlock();
}

## wait()

void Semaphore::wait | ( |  | ) |

Definition at line 23 of file thread.cc.

{
lock.lock();
waiting++;
while (count == 0)
cond.wait();
waiting--;
count--;
lock.unlock();
}

## 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:

- Singular/dyn_modules/systhreads/thread.h
- Singular/dyn_modules/systhreads/thread.cc