Xenomai
3.0.5
|
Counting semaphore IPC mechanism. More...
Data Structures | |
struct | RT_SEM_INFO |
Semaphore status descriptor. More... | |
Macros | |
#define | S_PRIO 0x1 /* Pend by task priority order. */ |
Creation flags. More... | |
Functions | |
int | rt_sem_create (RT_SEM *sem, const char *name, unsigned long icount, int mode) |
Create a counting semaphore. More... | |
int | rt_sem_delete (RT_SEM *sem) |
Delete a semaphore. More... | |
int | rt_sem_p_timed (RT_SEM *sem, const struct timespec *abs_timeout) |
Pend on a semaphore. More... | |
static int | rt_sem_p_until (RT_SEM *sem, RTIME timeout) |
Pend on a semaphore (with absolute scalar timeout). More... | |
static int | rt_sem_p (RT_SEM *sem, RTIME timeout) |
Pend on a semaphore (with relative scalar timeout). More... | |
int | rt_sem_v (RT_SEM *sem) |
Signal a semaphore. More... | |
int | rt_sem_broadcast (RT_SEM *sem) |
Broadcast a semaphore. More... | |
int | rt_sem_inquire (RT_SEM *sem, RT_SEM_INFO *info) |
Query semaphore status. More... | |
int | rt_sem_bind (RT_SEM *sem, const char *name, RTIME timeout) |
Bind to a semaphore. More... | |
int | rt_sem_unbind (RT_SEM *sem) |
Unbind from a semaphore. More... | |
Counting semaphore IPC mechanism.
A counting semaphore is a synchronization object for controlling the concurrency level allowed in accessing a resource from multiple real-time tasks, based on the value of a count variable accessed atomically. The semaphore is used through the P ("Proberen", from the Dutch "test and decrement") and V ("Verhogen", increment) operations. The P operation decrements the semaphore count by one if non-zero, or waits until a V operation is issued by another task. Conversely, the V operation releases a resource by incrementing the count by one, unblocking the heading task waiting on the P operation if any. Waiting on a semaphore may cause a priority inversion.
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, based on the priority inheritance protocol.
#define S_PRIO 0x1 /* Pend by task priority order. */ |
Creation flags.
int rt_sem_bind | ( | RT_SEM * | sem, |
const char * | name, | ||
RTIME | timeout | ||
) |
Bind to a semaphore.
This routine creates a new descriptor to refer to an existing semaphore identified by its symbolic name. If the object does not exist on entry, the caller may block until a semaphore of the given name is created.
sem | The address of a semaphore descriptor filled in by the operation. Contents of this memory is undefined upon failure. |
name | A valid NULL-terminated name which identifies the semaphore to bind to. This string should match the object name argument passed to rt_sem_create(). |
timeout | The number of clock ticks to wait for the registration to occur (see note). Passing TM_INFINITE causes the caller to block indefinitely until the object is registered. Passing TM_NONBLOCK causes the service to return immediately without waiting if the object is not registered on entry. |
int rt_sem_broadcast | ( | RT_SEM * | sem | ) |
Broadcast a semaphore.
All tasks currently waiting on the semaphore are immediately unblocked. The semaphore count is set to zero.
sem | The semaphore descriptor. |
int rt_sem_create | ( | RT_SEM * | sem, |
const char * | name, | ||
unsigned long | icount, | ||
int | mode | ||
) |
Create a counting semaphore.
sem | The address of a semaphore descriptor which can be later used to identify uniquely the created object, upon success of this call. |
name | An ASCII string standing for the symbolic name of the semaphore. When non-NULL and non-empty, a copy of this string is used for indexing the created semaphore into the object registry. |
icount | The initial value of the counting semaphore. |
mode | The semaphore creation mode. The following flags can be OR'ed into this bitmask: |
int rt_sem_delete | ( | RT_SEM * | sem | ) |
Delete a semaphore.
This routine deletes a semaphore previously created by a call to rt_sem_create().
sem | The semaphore descriptor. |
int rt_sem_inquire | ( | RT_SEM * | sem, |
RT_SEM_INFO * | info | ||
) |
Query semaphore status.
This routine returns the status information about the specified semaphore.
sem | The semaphore descriptor. |
info | A pointer to the returnbuffer" to copy the information to. |
|
inlinestatic |
Pend on a semaphore (with relative scalar timeout).
This routine is a variant of rt_sem_p_timed() accepting a relative timeout specification expressed as a scalar value.
sem | The semaphore descriptor. |
timeout | A delay expressed in clock ticks. |
References rt_sem_p_timed().
int rt_sem_p_timed | ( | RT_SEM * | sem, |
const struct timespec * | abs_timeout | ||
) |
Pend on a semaphore.
Test and decrement the semaphore count. 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 was required.
sem | The semaphore descriptor. |
abs_timeout | An absolute date expressed in clock ticks, specifying a time limit to wait for the request to be satisfied (see note). Passing NULL causes the caller to block indefinitely until the request is satisfied. Passing { .tv_sec = 0, .tv_nsec = 0 } causes the service to return without blocking in case the request cannot be satisfied immediately. |
Referenced by rt_sem_p(), and rt_sem_p_until().
|
inlinestatic |
Pend on a semaphore (with absolute scalar timeout).
This routine is a variant of rt_sem_p_timed() accepting an absolute timeout specification expressed as a scalar value.
sem | The semaphore descriptor. |
abs_timeout | An absolute date expressed in clock ticks. |
References rt_sem_p_timed().
int rt_sem_unbind | ( | RT_SEM * | sem | ) |
Unbind from a semaphore.
sem | The semaphore descriptor. |
This routine releases a previous binding to a semaphore. After this call has returned, the descriptor is no more valid for referencing this object.
int rt_sem_v | ( | RT_SEM * | sem | ) |
Signal a semaphore.
If the semaphore is pended, the task heading the wait queue is immediately unblocked. Otherwise, the semaphore count is incremented by one, unless the semaphore is used in "pulse" mode (see rt_sem_create()).
sem | The semaphore descriptor. |