74 create (key_t key_,
int initval_)
86 if (IPC_PRIVATE == key_) {
87 EL((
ASSAERR,
"Not intended for private semaphores\n"));
90 else if (key_ == (key_t) -1) {
91 EL((
ASSAERR,
"Probably an ftok() error by caller\n"));
99 if ( (
m_id = semget (
m_key, 3, 0666 | IPC_CREAT)) < 0) {
100 EL((
ASSAERR,
"Permission problem or kernel tables full\n"));
122 if (errno == EINVAL) {
135 if ((semval = semctl (
m_id, 1, GETVAL, 0)) < 0) {
148 semctrl_arg.val = initval_;
150 if (semctl (
m_id, 0, SETVAL, semctrl_arg) < 0) {
157 if (semctl (
m_id, 1, SETVAL, semctrl_arg) < 0) {
166 EL((
ASSAERR,
"Error on semop (ndcreate)\n"));
178 if (IPC_PRIVATE == key_) {
179 EL((
ASSAERR,
"Not intended for private semaphores\n"));
182 else if (key_ == (key_t) -1) {
183 EL((
ASSAERR,
"Probably an ftok() error by caller\n"));
208 if (
m_id < 0 ||
m_key == ((key_t) -1) )
return;
210 if (semctl (
m_id, 0, IPC_RMID, 0) < 0) {
225 if (
m_id < 0)
return;
239 if ((semval = semctl (
m_id, 1, GETVAL, 0)) < 0) {
273 if ((semval = semctl (
m_id, 1, GETVAL, 0)) < 0) {
280 if ((
m_op_op[0].sem_op = value_) == 0) {
281 EL((
ASSAERR,
"Can't have value_ == 0\n"));
297 std::ostringstream msg;
298 msg <<
"\n\n\tKey.....: ";
300 if (
m_key == (key_t) -1) {
304 msg <<
"0x" << std::hex <<
m_key << std::dec;
307 msg <<
"\n\tID......: " <<
m_id <<
"\n\n";
310 msg <<
"\tsemval [0]\tproc counter[1]\tlock [2]\n"
311 <<
"\t----------\t---------------\t--------\n";
314 msg <<
"\t " << semctl (
m_id, 0, GETVAL)
315 <<
"\t\t " << semctl (
m_id, 1, GETVAL)
316 <<
"\t\t " << semctl (
m_id, 2, GETVAL);
319 msg <<
"Semaphore id = -1. No info is available.";
322 DL((
SEM,
"%s\n\n", msg.str ().c_str ()));
#define Assure_exit(exp_)
Macro that makes program exit if assert fails.
#define EL(X)
A macro for writing error message to the Logger.
#define DL(X)
A macro for writing debug message to the Logger.
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Semaphore class provides a simpler and easier interface to System V semaphore system calls.
static sembuf m_op_open[2]
Decrement process counter with undo on exit.
void remove()
Remove a semaphore.
int create(key_t key_, int initval_=1)
Create a semaphore with a specified initial value.
void init()
Initalize by invalidating data members.
static sembuf m_op_op[1]
Decrement or increment semaphore with undo on exit.
static sembuf m_op_unlock[1]
Decremetn lock back to 0.
static sembuf m_op_close[3]
Wait for lock to equal 0, then increment lock to 1 (lock it), then increment process counter.
key_t m_key
Semaphore's key.
void op(int val_)
General semaphore operation.
static sembuf m_op_lock[2]
Wait for lock to equal 0, then increment lock to 1 - this locks it.
static const int BIGCOUNT
void dump(void) const
Dump the objects state along with the state of the semaphore (if connected) to the log file.
static sembuf m_op_endcreate[2]
Decrement process counter with undo on exit, then decrement lock back to 0.
void close()
Close a semaphore.
int open(key_t key_)
Open a semaphore that must already exist.
@ SEM
Class Semaphore messages
@ ASSAERR
ASSA and system errors
Socket & ends(Socket &os_)
ends manipulator.