My Project
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
LibThread::SingularSyncVar Class Reference

Public Member Functions

 SingularSyncVar ()
 
virtual ~SingularSyncVar ()
 
void acquire ()
 
void release ()
 
void wait_init ()
 
leftv get ()
 
void update (leftv val)
 
int write (string item)
 
string read ()
 
int check ()
 
- 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

string value
 
int init
 
Lock lock
 
ConditionVariable cond
 

Detailed Description

Definition at line 431 of file shared.cc.

Constructor & Destructor Documentation

◆ SingularSyncVar()

LibThread::SingularSyncVar::SingularSyncVar ( )
inline

Definition at line 438 of file shared.cc.

◆ ~SingularSyncVar()

virtual LibThread::SingularSyncVar::~SingularSyncVar ( )
inlinevirtual

Definition at line 439 of file shared.cc.

439{ }

Member Function Documentation

◆ acquire()

void LibThread::SingularSyncVar::acquire ( )
inline

Definition at line 440 of file shared.cc.

440 {
441 lock.lock();
442 }
void lock()
Definition: thread.h:46

◆ check()

int LibThread::SingularSyncVar::check ( )
inline

Definition at line 479 of file shared.cc.

479 {
480 lock.lock();
481 int result = init;
482 lock.unlock();
483 return result;
484 }
void unlock()
Definition: thread.h:57
return result
Definition: facAbsBiFact.cc:75

◆ get()

leftv LibThread::SingularSyncVar::get ( )
inline

Definition at line 450 of file shared.cc.

450 {
451 if (value.size() == 0) return NULL;
453 }
leftv from_string(std::string &str)
Definition: lintree.cc:854
#define NULL
Definition: omList.c:12

◆ read()

string LibThread::SingularSyncVar::read ( )
inline

Definition at line 471 of file shared.cc.

471 {
472 lock.lock();
473 while (!init)
474 cond.wait();
475 string result = value;
476 lock.unlock();
477 return result;
478 }
void wait()
Definition: thread.h:88

◆ release()

void LibThread::SingularSyncVar::release ( )
inline

Definition at line 443 of file shared.cc.

443 {
444 lock.unlock();
445 }

◆ update()

void LibThread::SingularSyncVar::update ( leftv  val)
inline

Definition at line 454 of file shared.cc.

454 {
456 init = 1;
457 cond.broadcast();
458 }
void broadcast()
Definition: thread.h:103
std::string to_string(leftv val)
Definition: lintree.cc:843

◆ wait_init()

void LibThread::SingularSyncVar::wait_init ( )
inline

Definition at line 446 of file shared.cc.

446 {
447 while (!init)
448 cond.wait();
449 }

◆ write()

int LibThread::SingularSyncVar::write ( string  item)
inline

Definition at line 459 of file shared.cc.

459 {
460 int result = 0;
461 lock.lock();
462 if (!init) {
463 value = item;
464 init = 1;
465 cond.broadcast();
466 result = 1;
467 }
468 lock.unlock();
469 return result;
470 }

Field Documentation

◆ cond

ConditionVariable LibThread::SingularSyncVar::cond
private

Definition at line 436 of file shared.cc.

◆ init

int LibThread::SingularSyncVar::init
private

Definition at line 434 of file shared.cc.

◆ lock

Lock LibThread::SingularSyncVar::lock
private

Definition at line 435 of file shared.cc.

◆ value

string LibThread::SingularSyncVar::value
private

Definition at line 433 of file shared.cc.


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