Loading...
Searching...
No Matches
LibThread::SyncVar< T > Class Template Reference

`#include <syncvar.h>`

## Public Member Functions

| SyncVar ()
void | write (T &value)
void | read (T &result)
bool | try_read (T &result)

## Private Attributes

Lock | lock
ConditionVariable | cond
int | waiting
bool | init
T | value

## Detailed Description

template<typename T>
class LibThread::SyncVar< T >

Definition at line 11 of file syncvar.h.

## Constructor & Destructor Documentation

## SyncVar()

template<typename T>

LibThread::SyncVar< T >::SyncVar | ( |  | ) |

inline

Definition at line 19 of file syncvar.h.

: lock(), cond(&lock), waiting(0), init(false) {
}
LibThread::SyncVar::waiting
int waiting
Definition syncvar.h:15
LibThread::SyncVar::init
bool init
Definition syncvar.h:16
LibThread::SyncVar::lock
Lock lock
Definition syncvar.h:13
LibThread::SyncVar::cond
ConditionVariable cond
Definition syncvar.h:14

## Member Function Documentation

## read()

template<typename T>

void LibThread::SyncVar< T >::read | ( | T & | result | ) |

inline

Definition at line 31 of file syncvar.h.

{
lock.lock();
waiting++;
while (!init)
cond.wait();
waiting--;
if (waiting)
cond.signal();
lock.unlock();
}

## try_read()

template<typename T>

bool LibThread::SyncVar< T >::try_read | ( | T & | result | ) |

inline

Definition at line 41 of file syncvar.h.

{
bool success;
lock.lock();
success = init;
if (success) {
result = value;
}
lock.unlock();
return success;
}
LibThread::SyncVar
Definition syncvar.h:11
LibThread::SyncVar::value
T value
Definition syncvar.h:17

## write()

template<typename T>

void LibThread::SyncVar< T >::write | ( | T & | value | ) |

inline

Definition at line 21 of file syncvar.h.

{
lock.lock();
if (!init) {
this->value = value;
this->init = true;
}
if (waiting)
cond.signal();
lock.unlock();
}

## Field Documentation

## cond

template<typename T>

ConditionVariable LibThread::SyncVar< T >::cond

private

Definition at line 14 of file syncvar.h.

## init

template<typename T>

bool LibThread::SyncVar< T >::init

private

Definition at line 16 of file syncvar.h.

## lock

template<typename T>

Lock LibThread::SyncVar< T >::lock

private

Definition at line 13 of file syncvar.h.

## value

template<typename T>

T LibThread::SyncVar< T >::value

private

Definition at line 17 of file syncvar.h.

## waiting

template<typename T>

int LibThread::SyncVar< T >::waiting

private

Definition at line 15 of file syncvar.h.

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

- Singular/dyn_modules/systhreads/syncvar.h