libHartwer - Documentation
Functions

bcs_semaphore.h File Reference

Mapping for different semaphore implementations. More...

Go to the source code of this file.

Functions

BCS_ERROR BCS_sem_close (BCS_Semaphore sem)
 The system resources associated with the named semaphore referenced by sem are deallocated and the descriptor is invali- dated.
BCS_Semaphore BCS_sem_open (const char *name, int oflag, int mode, int initial)
 The named semaphore named name is initialized and opened as specified by the argument oflag and a semaphore descriptor is returned to the calling process.
BCS_ERROR BCS_sem_post (BCS_Semaphore sem)
 The semaphore referenced by sem is unlocked, the value of the semaphore is incremented, and all threads which are waiting on the semaphore are awakened.
BCS_ERROR BCS_sem_trywait (BCS_Semaphore sem)
 The semaphore referenced by sem is locked.
BCS_ERROR BCS_sem_unlink (const char *name)
 The named semaphore named name is removed.
BCS_ERROR BCS_sem_wait (BCS_Semaphore sem)
 The semaphore referenced by sem is locked.

Detailed Description

Date:
28.07.2010
Author:
Elefant Racing This file is providing an independent mapping for different semaphore implementations. This way you can easily switch between them due to performance issues, weird behaviour or simply other platforms.

Currently supported are:


Function Documentation

BCS_ERROR BCS_sem_close ( BCS_Semaphore  sem) [inline]

If successful, BCS_sem_close() will return BCS_ERR_OK. Otherwise, an error value is returned.

Parameters:
semYour semaphore
BCS_Semaphore BCS_sem_open ( const char *  name,
int  oflag,
int  mode,
int  initial 
)

The value of oflag is formed by or'ing the following values:

O_CREAT create the semaphore if it does not exist O_EXCL error if create and semaphore exists

If O_CREAT is specified, BCS_sem_open() requires an additional two arguments. mode specifies the permissions for the sema- phore as described in chmod(2) and modified by the process' umask value (see umask(2)). The semaphore is created with an initial value, which must be less than or equal to BCS_SEM_VALUE_MAX.

In case O_CREAT is not specified, simply pass any value to mode and initial, it will be ignored.

If O_EXCL is specified and the semaphore exists, BCS_sem_open() fails. The check for the existence of the semaphore and the creation of the semaphore are atomic with respect to all processes calling BCS_sem_open() with O_CREAT and O_EXCL set.

When a new semaphore is created, it is given the user ID and group ID which correspond to the effective user and group IDs of the calling process. There is no visible entry in the file system for the created object in this implementation.

The returned semaphore descriptor is available to the calling process until it is closed with BCS_sem_close(), or until the caller exits or execs.

If a process makes repeated calls to BCS_sem_open(), with the same name argument, the same descriptor is returned for each successful call, unless BCS_sem_unlink() has been called on the semaphore in the interim.

If BCS_sem_open() fails for any reason, it will return a value of BCS_SEM_FAILED and sets errno. On success, it returns a sema- phore descriptor.

BCS_ERROR BCS_sem_post ( BCS_Semaphore  sem) [inline]

BCS_sem_post() is reentrant with respect to signals and may be called from within a signal hanlder.

If successful, BCS_sem_post() will return BCS_ERR_OK. Otherwise, an error value is returned, and the state of the semaphore is unchanged.

Parameters:
semYour semaphore
BCS_ERROR BCS_sem_trywait ( BCS_Semaphore  sem) [inline]

When calling BCS_sem_wait(), if the semaphore's value is zero, the calling thread will block until the lock is acquired or until the call is interrupted by a signal. Alternatively, the BCS_sem_trywait() func- tion will fail if the semaphore is already locked, rather than blocking on the semaphore.

If successful (the lock was acquired), BCS_sem_wait() and BCS_sem_trywait() will return BCS_ERR_OK. Otherwise, an error value is returned, and the state of the semaphore is unchanged.

Parameters:
semYour semaphore
BCS_ERROR BCS_sem_unlink ( const char *  name) [inline]

If the semaphore is in use by other processes, then name is immediately disas- sociated with the semaphore, but the semaphore itself will not be removed until all references to it have been closed. Subsequent calls to BCS_sem_open() using name will refer to or create a new semaphore named name.

If successful, BCS_sem_unlink() will return BCS_ERR_OK. Otherwise, error code is returned, and the state of the semaphore is unchanged.

BCS_ERROR BCS_sem_wait ( BCS_Semaphore  sem) [inline]

When calling BCS_sem_wait(), if the semaphore's value is zero, the calling thread will block until the lock is acquired or until the call is interrupted by a signal. Alternatively, the BCS_sem_trywait() func- tion will fail if the semaphore is already locked, rather than blocking on the semaphore.

If successful (the lock was acquired), BCS_sem_wait() and BCS_sem_trywait() will return BCS_ERR_OK. Otherwise, an error value is returned, and the state of the semaphore is unchanged.

Parameters:
semYour semaphore

Generated on Fri Feb 11 2011 18:25:46 for libHartwer by Doxygen 1.7.3
Content © 2009-2011 Elefant Racing Bayreuth & MLBA (About) – Design © 2010 Emzeat. All Rights reserved.