My Project
Public Member Functions | Private Attributes
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< Tq
 

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.

18  : lock(), cond(&lock), waiting(0), q() {
19  }
std::queue< T > q
Definition: channel.h:16
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.

38  {
39  T result;
40  receive(&result);
41  return result;
42  }
return result
Definition: facAbsBiFact.cc:75
STATIC_VAR jList * T
Definition: janet.cc:30

◆ receive() [2/2]

template<typename T >
void LibThread::Channel< T >::receive ( T result)
inline

Definition at line 27 of file channel.h.

27  {
28  lock.lock();
29  waiting++;
30  while (q.empty())
31  cond.wait();
32  result = q.pop();
33  waiting--;
34  if (waiting)
35  cond.signal();
36  lock.unlock();
37  }
void wait()
Definition: thread.h:88
void signal()
Definition: thread.h:97
void lock()
Definition: thread.h:46
void unlock()
Definition: thread.h:57

◆ send()

template<typename T >
void LibThread::Channel< T >::send ( T value)
inline

Definition at line 20 of file channel.h.

20  {
21  lock.lock();
22  q.push(value);
23  if (waiting)
24  cond.signal();
25  lock.unlock();
26  }

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: