Loading...
Searching...
No Matches
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 426 of file shared.cc.

## Constructor & Destructor Documentation

## SingularSyncVar()

LibThread::SingularSyncVar::SingularSyncVar | ( |  | ) |

inline

Definition at line 433 of file shared.cc.

: SharedObject(), init(0), lock(), cond(&lock) { }
LibThread::SharedObject::SharedObject
SharedObject()
Definition shared.cc:156
LibThread::SingularSyncVar::cond
ConditionVariable cond
Definition shared.cc:431
LibThread::SingularSyncVar::init
int init
Definition shared.cc:429
LibThread::SingularSyncVar::lock
Lock lock
Definition shared.cc:430

## ~SingularSyncVar()

virtual LibThread::SingularSyncVar::~SingularSyncVar | ( |  | ) |

inline virtual

Definition at line 434 of file shared.cc.

{ }

## Member Function Documentation

## acquire()

void LibThread::SingularSyncVar::acquire | ( |  | ) |

inline

Definition at line 435 of file shared.cc.

{
lock.lock();
}

## check()

int LibThread::SingularSyncVar::check | ( |  | ) |

inline

Definition at line 474 of file shared.cc.

{
lock.lock();
int result = init;
lock.unlock();
return result;
}
result
return result
Definition facAbsBiFact.cc:76

## get()

leftv LibThread::SingularSyncVar::get | ( |  | ) |

inline

Definition at line 445 of file shared.cc.

{
if (value.size() == 0) return NULL;
return LinTree::from_string(value);
}
LibThread::SingularSyncVar::value
string value
Definition shared.cc:428
LinTree::from_string
leftv from_string(std::string &str)
Definition lintree.cc:854
NULL
#define NULL
Definition omList.c:12

## read()

string LibThread::SingularSyncVar::read | ( |  | ) |

inline

Definition at line 466 of file shared.cc.

{
lock.lock();
while (!init)
cond.wait();
string result = value;
lock.unlock();
return result;
}

## release()

void LibThread::SingularSyncVar::release | ( |  | ) |

inline

Definition at line 438 of file shared.cc.

{
lock.unlock();
}

## update()

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

inline

Definition at line 449 of file shared.cc.

{
value = LinTree::to_string(val);
init = 1;
cond.broadcast();
}
LinTree::to_string
std::string to_string(leftv val)
Definition lintree.cc:843

## wait_init()

void LibThread::SingularSyncVar::wait_init | ( |  | ) |

inline

Definition at line 441 of file shared.cc.

{
while (!init)
cond.wait();
}

## write()

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

inline

Definition at line 454 of file shared.cc.

{
int result = 0;
lock.lock();
if (!init) {
value = item;
init = 1;
cond.broadcast();
result = 1;
}
lock.unlock();
return result;
}

## Field Documentation

## cond

ConditionVariable LibThread::SingularSyncVar::cond

private

Definition at line 431 of file shared.cc.

## init

int LibThread::SingularSyncVar::init

private

Definition at line 429 of file shared.cc.

## lock

Lock LibThread::SingularSyncVar::lock

private

Definition at line 430 of file shared.cc.

## value

string LibThread::SingularSyncVar::value

private

Definition at line 428 of file shared.cc.

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

- Singular/dyn_modules/systhreads/shared.cc