psem is a quick and dirty encapsulation of the system V sem utility
protected data members for access from derived class
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 systemCOMMENTS:
- this is a crude implementation, one can add more functionality later (such as resizing, ownership, etc....)
- Access modes for changing the semaphores:
psem as UNIX semaphores knows 2 modes, IPC_NOWAIT and SEM_UNDO. We encapsulate this into our own modes and move the system V stuff into the member function.
Define 3 modes:
DEFAULT_MODE (which defaults to the private data member default_mode)
UNDO_MODE
NOWAIT_MODE- Difference between incr/decr and lock/unlock: in calling lock/unlock we assume we are using the semaphore really as a lock ,i.e. we use UNDO_MODE.
MODIFICATIONS:
static int remove(int id)
static int exists( int nb_sem, key_t my_key, char *filename )
int decr(int isem, int mode = DEFAULT_MODE)
int incr(int isem, int mode = DEFAULT_MODE)
int add(int isem, int ival, int mode = DEFAULT_MODE)
int sub(int isem, int ival, int mode = DEFAULT_MODE)
int lock(int isem)
int unlock(int isem)
int set_sem( int isem, int sem_val )
int set_all_sem( int sem_val )
int get_sem( int isem )
int get_sem_values(int &nb_sem, int *&values)
void set_mode( int mode )
int get_mode()
int get_nproc_waiting(int isem)
int default_mode
void addToCleanupScript( int theId )
this page has been generated automatically by doc++
(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de