My Project
Loading...
Searching...
No Matches
LibThread::SingularChannel Class Reference

Public Member Functions

 SingularChannel ()
 
virtual ~SingularChannel ()
 
void send (string item)
 
string receive ()
 
long count ()
 
- Public Member Functions inherited from LibThread::SharedObject
 SharedObject ()
 
virtual ~SharedObject ()
 
void set_type (int type_init)
 
int get_type ()
 
void set_name (std::string &name_init)
 
void set_name (const char *s)
 
std::string & get_name ()
 
void incref (int by=1)
 
long decref ()
 
long getref ()
 
virtual BOOLEAN op2 (int op, leftv res, leftv a1, leftv a2)
 
virtual BOOLEAN op3 (int op, leftv res, leftv a1, leftv a2, leftv a3)
 

Private Attributes

queue< string > q
 
Lock lock
 
ConditionVariable cond
 

Detailed Description

Definition at line 392 of file shared.cc.

Constructor & Destructor Documentation

◆ SingularChannel()

LibThread::SingularChannel::SingularChannel ( )
inline

Definition at line 398 of file shared.cc.

◆ ~SingularChannel()

virtual LibThread::SingularChannel::~SingularChannel ( )
inlinevirtual

Definition at line 399 of file shared.cc.

399{ }

Member Function Documentation

◆ count()

long LibThread::SingularChannel::count ( )
inline

Definition at line 418 of file shared.cc.

418 {
419 lock.lock();
420 long result = q.size();
421 lock.unlock();
422 return result;
423 }
queue< string > q
Definition shared.cc:394
return result

◆ receive()

string LibThread::SingularChannel::receive ( )
inline

Definition at line 406 of file shared.cc.

406 {
407 lock.lock();
408 while (q.empty()) {
409 cond.wait();
410 }
411 string result = q.front();
412 q.pop();
413 if (!q.empty())
414 cond.signal();
415 lock.unlock();
416 return result;
417 }

◆ send()

void LibThread::SingularChannel::send ( string item)
inline

Definition at line 400 of file shared.cc.

400 {
401 lock.lock();
402 q.push(item);
403 cond.signal();
404 lock.unlock();
405 }

Field Documentation

◆ cond

ConditionVariable LibThread::SingularChannel::cond
private

Definition at line 396 of file shared.cc.

◆ lock

Lock LibThread::SingularChannel::lock
private

Definition at line 395 of file shared.cc.

◆ q

queue<string> LibThread::SingularChannel::q
private

Definition at line 394 of file shared.cc.


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