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. |
Currently supported are:
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.
sem | Your 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.
sem | Your 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.
sem | Your 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.
sem | Your semaphore |