libassa
3.5.1
|
#include <Semaphore.h>
Public Member Functions | |
Semaphore () | |
Constructor. More... | |
virtual | ~Semaphore () |
Destructor. More... | |
int | create (key_t key_, int initval_=1) |
Create a semaphore with a specified initial value. More... | |
int | open (key_t key_) |
Open a semaphore that must already exist. More... | |
void | close () |
Close a semaphore. More... | |
void | remove () |
Remove a semaphore. More... | |
void | wait () |
Wait until a semaphore's value is greater then 0, then decrement it by 1 and return. More... | |
void | signal () |
Increment a semaphore by 1. More... | |
void | op (int val_) |
General semaphore operation. More... | |
key_t | key () const |
Get key. More... | |
int | id () const |
Get id. More... | |
void | dump (void) const |
Dump the objects state along with the state of the semaphore (if connected) to the log file. More... | |
Protected Member Functions | |
void | init () |
Initalize by invalidating data members. More... | |
Protected Attributes | |
key_t | m_key |
Semaphore's key. More... | |
int | m_id |
Semaphore's id. More... | |
Static Protected Attributes | |
static const int | BIGCOUNT = 10000 |
static sembuf | m_op_lock [2] |
Wait for lock to equal 0, then increment lock to 1 - this locks it. More... | |
static sembuf | m_op_endcreate [2] |
Decrement process counter with undo on exit, then decrement lock back to 0. More... | |
static sembuf | m_op_open [2] |
Decrement process counter with undo on exit. More... | |
static sembuf | m_op_close [3] |
Wait for lock to equal 0, then increment lock to 1 (lock it), then increment process counter. More... | |
static sembuf | m_op_unlock [1] |
Decremetn lock back to 0. More... | |
static sembuf | m_op_op [1] |
Decrement or increment semaphore with undo on exit. More... | |
Definition at line 67 of file Semaphore.h.
|
inline |
Constructor.
Definition at line 190 of file Semaphore.h.
References init(), ASSA::SEM, and trace_with_mask.
|
inlinevirtual |
Destructor.
Definition at line 199 of file Semaphore.h.
References close(), m_id, ASSA::SEM, and trace_with_mask.
void Semaphore::close | ( | void | ) |
Close a semaphore.
Unlike the Semaphore::remove () function, this function is for a process to call before it exits, when it is done with the semaphore. We decrement the counter of processes using the semaphore, and if this was the last one, Semaphore::remove () is called to remove the semaphore. Calling this method also invalidates object for subsequent operations.
Definition at line 218 of file Semaphore.cpp.
References ASSA::ASSAERR, Assure_exit, BIGCOUNT, EL, init(), m_id, m_op_close, m_op_unlock, remove(), ASSA::SEM, and trace_with_mask.
Referenced by ~Semaphore().
int Semaphore::create | ( | key_t | key_, |
int | initval_ = 1 |
||
) |
Create a semaphore with a specified initial value.
If the semaphore already exists, we don't initialize it (of course).
key_ | Semaphore's key |
initval_ | Initiali value (default : 1) |
Definition at line 73 of file Semaphore.cpp.
References ASSA::ASSAERR, Assure_exit, BIGCOUNT, EL, m_id, m_key, m_op_endcreate, m_op_lock, ASSA::SEM, and trace_with_mask.
void Semaphore::dump | ( | void | ) | const |
Dump the objects state along with the state of the semaphore (if connected) to the log file.
Definition at line 292 of file Semaphore.cpp.
References DL, ASSA::ends(), m_id, m_key, ASSA::SEM, and trace_with_mask.
Referenced by op().
|
inline |
|
inlineprotected |
Initalize by invalidating data members.
Definition at line 210 of file Semaphore.h.
Referenced by close(), remove(), and Semaphore().
|
inline |
void Semaphore::op | ( | int | val_ | ) |
General semaphore operation.
Increment or decrement by a user-specified amount (positive or negative; amount can't be zero!).
Definition at line 261 of file Semaphore.cpp.
References ASSA::ASSAERR, Assure_exit, dump(), EL, m_id, m_op_op, ASSA::SEM, and trace_with_mask.
int Semaphore::open | ( | key_t | key_ | ) |
Open a semaphore that must already exist.
This function should be used, instead of Semaphore::create (), if the caller knows that the semaphore must already exist. For example, a client from a client-server pair would use this, if its server's responsibility to create the semaphore.
key_ | Semaphore's key |
Definition at line 173 of file Semaphore.cpp.
References ASSA::ASSAERR, Assure_exit, EL, m_id, m_key, m_op_open, ASSA::SEM, and trace_with_mask.
void Semaphore::remove | ( | ) |
Remove a semaphore.
This call is intended to be called by a server, for example, when it is being shut down, as we do an IPC_RMID on the semaphore, regardless whether other processes may be using it or not. Most other processes should use Semaphore::close () instead. Calling this method also invalidates object for subsequent operations.
Definition at line 203 of file Semaphore.cpp.
References ASSA::ASSAERR, Assure_exit, EL, init(), m_id, m_key, ASSA::SEM, and trace_with_mask.
Referenced by close().
|
inline |
Increment a semaphore by 1.
Tanenbaum's UP operation.
Definition at line 226 of file Semaphore.h.
References op(), ASSA::SEM, and trace_with_mask.
|
inline |
Wait until a semaphore's value is greater then 0, then decrement it by 1 and return.
Tanenbaum's DOWN operation.
Definition at line 218 of file Semaphore.h.
References op(), ASSA::SEM, and trace_with_mask.
|
staticprotected |
Definition at line 157 of file Semaphore.h.
|
protected |
|
protected |
|
staticprotected |
Wait for lock to equal 0, then increment lock to 1 (lock it), then increment process counter.
Definition at line 176 of file Semaphore.h.
Referenced by close().
|
staticprotected |
Decrement process counter with undo on exit, then decrement lock back to 0.
Definition at line 166 of file Semaphore.h.
Referenced by create().
|
staticprotected |
Wait for lock to equal 0, then increment lock to 1 - this locks it.
Definition at line 161 of file Semaphore.h.
Referenced by create().
|
staticprotected |
Decrement or increment semaphore with undo on exit.
The 99 is set to the actual amount to add or substract (positive or negative).
Definition at line 186 of file Semaphore.h.
Referenced by op().
|
staticprotected |
Decrement process counter with undo on exit.
Definition at line 171 of file Semaphore.h.
Referenced by open().
|
staticprotected |
Decremetn lock back to 0.
Definition at line 180 of file Semaphore.h.
Referenced by close().