class psem : public pipc

psem is a quick and dirty encapsulation of the system V sem utility

Inheritance:


Public Methods

int add(int isem, int ival, int mode = DEFAULT_MODE)
adds ival to the semaphore isem
int decr(int isem, int mode = DEFAULT_MODE)
decrements the semaphore isem with mode
static int exists( int nb_sem, key_t my_key, char *filename )
returns true if it exists
int get_mode()
returns the default access mode
int get_nproc_waiting(int isem)
returns the number of processes waiting for the semaphore to change
int get_sem( int isem )
returns the value of the semaphore isem
int get_sem_values(int &nb_sem, int *&values)
get all semaphores, client responsible for deleting the returned array
int incr(int isem, int mode = DEFAULT_MODE)
increments the semaphore isem in the set
int lock(int isem)
locks the semaphore (i.e. decr with SEM_UNDO )
psem(int nb_sem, int init_val = 0, key_t key = 1, char *filename = NULL)
creates a semaphore set with nb_sem semaphores and initialises it to init_val
static int remove(int id)
forces the removal of the IPC with identifier id
int set_all_sem( int sem_val )
set all semaphore in the set to the value sem_val
void set_mode( int mode )
sets the default access mode
int set_sem( int isem, int sem_val )
set semaphore isem to the value sem_val
int sub(int isem, int ival, int mode = DEFAULT_MODE)
subtracts ival from the semaphore isem
int unlock(int isem)
unlocks the semaphore (i.e. incr with SEM_UNDO)

Private Fields

int default_mode
the default mode of the semaphore - determines how the emaphore is manipulates

Private Methods

void addToCleanupScript( int theId )
Routine to be called to add an entry for cleaning up the semaphore from the cleanup script

Inherited from pipc:

Public Methods

int get_id()
key_t get_key()
int get_size()
int get_status()
int i_created()

Protected Methods

static key_t get_existing_key( char *filename, key_t key )
static key_t get_key( char *filename, key_t key = 1, int create = -1 )
static key_t get_new_key( char *filename, key_t key )

Protected

protected data members for access from derived class

int id
identifier
int size
size
key_t key
the unique key
int status
status of the last command
time_t time_created
time when the resource was created
int created
whether the process was the one that created the resource (or just attached to it)
static char* pcIpcCleanupFile
Pointer to the cleanup file name that has to be created if we want to have a script at the end that eliminates all IPC resources

Documentation

psem is a quick and dirty encapsulation of the system V sem utility.

Usage:

 psem *sem = new psem(size) for just getting one shm of size size
           = new psem(size, my_key) if you want to get more than
                           one shm per user, you must specify
                           the key for each shm
           = new psem(size, key, project) if you want to share
                           different shm between different users
                           [project is the environment variable HOME by default]
           Note: you must test status after constructing the
                 shm for == 0 to make sure it worked!
                 [We want to avoid exception handling as long
                 as we use irix 5.3]

 delete psem : to deattach (but not delete the shm)

 static int psem::remove(int shmid) to remove the shmid
                         from the system

 

COMMENTS:

MODIFICATIONS:

psem(int nb_sem, int init_val = 0, key_t key = 1, char *filename = NULL)
creates a semaphore set with nb_sem semaphores and initialises it to init_val

static int remove(int id)
forces the removal of the IPC with identifier id

static int exists( int nb_sem, key_t my_key, char *filename )
returns true if it exists

int decr(int isem, int mode = DEFAULT_MODE)
decrements the semaphore isem with mode

int incr(int isem, int mode = DEFAULT_MODE)
increments the semaphore isem in the set

int add(int isem, int ival, int mode = DEFAULT_MODE)
adds ival to the semaphore isem

int sub(int isem, int ival, int mode = DEFAULT_MODE)
subtracts ival from the semaphore isem

int lock(int isem)
locks the semaphore (i.e. decr with SEM_UNDO )

int unlock(int isem)
unlocks the semaphore (i.e. incr with SEM_UNDO)

int set_sem( int isem, int sem_val )
set semaphore isem to the value sem_val

int set_all_sem( int sem_val )
set all semaphore in the set to the value sem_val

int get_sem( int isem )
returns the value of the semaphore isem

int get_sem_values(int &nb_sem, int *&values)
get all semaphores, client responsible for deleting the returned array

void set_mode( int mode )
sets the default access mode

int get_mode()
returns the default access mode

int get_nproc_waiting(int isem)
returns the number of processes waiting for the semaphore to change

int default_mode
the default mode of the semaphore - determines how the emaphore is manipulates

void addToCleanupScript( int theId )
Routine to be called to add an entry for cleaning up the semaphore from the cleanup script


This class has no child classes.
Author:
C.Witzig
Date: May 4, 97
Version:
Last update May 4, 97

alphabetic index hierarchy of classes


this page has been generated automatically by doc++

(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de