Loading...
Searching...
No Matches
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
Lock * | lock
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 | ( |  | ) |

inline private

Definition at line 80 of file thread.h.

{ }

## ConditionVariable() [2/2]

ConditionVariable::ConditionVariable | ( | Lock * | lock_init | ) |

inline

Definition at line 82 of file thread.h.

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

## ~ConditionVariable()

ConditionVariable::~ConditionVariable | ( |  | ) |

inline

Definition at line 85 of file thread.h.

{
pthread_cond_destroy(&condition);
}

## Member Function Documentation

## broadcast()

void ConditionVariable::broadcast | ( |  | ) |

inline

Definition at line 103 of file thread.h.

{
if (!lock->is_locked())
ThreadError("signaled condition without locked mutex");
if (waiting)
pthread_cond_broadcast(&condition);
}
ThreadError
void ThreadError(const char *message)
Definition thread.cc:18

## signal()

void ConditionVariable::signal | ( |  | ) |

inline

Definition at line 97 of file thread.h.

{
if (!lock->is_locked())
ThreadError("signaled condition without locked mutex");
if (waiting)
pthread_cond_signal(&condition);
}

## wait()

void ConditionVariable::wait | ( |  | ) |

inline

Definition at line 88 of file thread.h.

{
if (!lock->is_locked())
ThreadError("waited on condition without locked mutex");
waiting++;
int l = lock->break_lock();
pthread_cond_wait(&condition, &lock->mutex);
waiting--;
lock->resume_lock(l);
}
l
int l
Definition cfEzgcd.cc:100

## Friends And Related Symbol 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:

- Singular/dyn_modules/systhreads/thread.h