If no more than a single resource is made available at any point in time, the semaphore enforces mutual exclusion and thus can be used to serialize access to a critical section. However, mutexes should be used instead in order to prevent priority inversions.
Files | |
file | sem.c |
This file is part of the Xenomai project. | |
Functions | |
int | rt_sem_create (RT_SEM *sem, const char *name, unsigned long icount, int mode) |
Create a counting semaphore. | |
int | rt_sem_delete (RT_SEM *sem) |
Delete a semaphore. | |
int | rt_sem_p (RT_SEM *sem, RTIME timeout) |
Pend on a semaphore. | |
int | rt_sem_v (RT_SEM *sem) |
Signal a semaphore. | |
int | rt_sem_broadcast (RT_SEM *sem) |
Broadcast a semaphore. | |
int | rt_sem_inquire (RT_SEM *sem, RT_SEM_INFO *info) |
Inquire about a semaphore. | |
int | rt_sem_bind (RT_SEM *sem, const char *name, RTIME timeout) |
Bind to a semaphore. | |
static int | rt_sem_unbind (RT_SEM *sem) |
Unbind from a semaphore. |
|
Bind to a semaphore. This user-space only service retrieves the uniform descriptor of a given Xenomai semaphore identified by its symbolic name. If the semaphore does not exist on entry, this service blocks the caller until a semaphore of the given name is created.
Environments: This service can be called from:
Rescheduling: always unless the request is immediately satisfied or timeout specifies a non-blocking operation.
|
|
Broadcast a semaphore. Unblock all tasks waiting on a semaphore. Awaken tasks return from rt_sem_p() as if the semaphore has been signaled. The semaphore count is zeroed as a result of the operation.
Environments: This service can be called from:
Rescheduling: possible. |
|
Create a counting semaphore.
Environments: This service can be called from:
Rescheduling: possible. |
|
Delete a semaphore. Destroy a semaphore and release all the tasks currently pending on it. A semaphore exists in the system since rt_sem_create() has been called to create it, so this service must be called in order to destroy it afterwards.
Environments: This service can be called from:
Rescheduling: possible. |
|
Inquire about a semaphore. Return various information about the status of a given semaphore.
Environments: This service can be called from:
Rescheduling: never. |
|
Pend on a semaphore. Acquire a semaphore unit. If the semaphore value is greater than zero, it is decremented by one and the service immediately returns to the caller. Otherwise, the caller is blocked until the semaphore is either signaled or destroyed, unless a non-blocking operation has been required.
Environments: This service can be called from:
Rescheduling: always unless the request is immediately satisfied or timeout specifies a non-blocking operation.
|
|
Unbind from a semaphore. This user-space only service unbinds the calling task from the semaphore object previously retrieved by a call to rt_sem_bind().
Rescheduling: never. |
|
Signal a semaphore. Release a semaphore unit. If the semaphore is pended, the first waiting task (by queuing order) is immediately unblocked; otherwise, the semaphore value is incremented by one.
Environments: This service can be called from:
Rescheduling: possible. |