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

`#include <channel.h>`

## Public Member Functions

| Channel ()
void | send (T &value)
void | receive (T &result)
T | receive ()

## Private Attributes

Lock | lock
ConditionVariable | cond
int | waiting
std::queue< T > | q

## Detailed Description

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

Definition at line 11 of file channel.h.

## Constructor & Destructor Documentation

## Channel()

template<typename T>

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

inline

Definition at line 18 of file channel.h.

: lock(), cond(&lock), waiting(0), q() {
}
LibThread::Channel::q
std::queue< T > q
Definition channel.h:16
LibThread::Channel::lock
Lock lock
Definition channel.h:13
LibThread::Channel::waiting
int waiting
Definition channel.h:15
LibThread::Channel::cond
ConditionVariable cond
Definition channel.h:14

## Member Function Documentation

## receive() [1/2]

template<typename T>

T LibThread::Channel< T >::receive | ( |  | ) |

inline

Definition at line 38 of file channel.h.

{
T result;
receive(&result);
return result;
}
LibThread::Channel
Definition channel.h:11
LibThread::Channel::receive
T receive()
Definition channel.h:38

## receive() [2/2]

template<typename T>

void LibThread::Channel< T >::receive | ( | T & | result | ) |

inline

Definition at line 27 of file channel.h.

{
lock.lock();
waiting++;
while (q.empty())
cond.wait();
result = q.pop();
waiting--;
if (waiting)
cond.signal();
lock.unlock();
}

## send()

template<typename T>

void LibThread::Channel< T >::send | ( | T & | value | ) |

inline

Definition at line 20 of file channel.h.

{
lock.lock();
q.push(value);
if (waiting)
cond.signal();
lock.unlock();
}

## Field Documentation

## cond

template<typename T>

ConditionVariable LibThread::Channel< T >::cond

private

Definition at line 14 of file channel.h.

## lock

template<typename T>

Lock LibThread::Channel< T >::lock

private

Definition at line 13 of file channel.h.

## q

template<typename T>

std::queue<T> LibThread::Channel< T >::q

private

Definition at line 16 of file channel.h.

## waiting

template<typename T>

int LibThread::Channel< T >::waiting

private

Definition at line 15 of file channel.h.

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

- Singular/dyn_modules/systhreads/channel.h