Xenomai API
2.5.6.1
|
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_p_until (RT_SEM *sem, RTIME timeout) |
Pend on a semaphore (with absolute timeout date). | |
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. |
A counting semaphore is a synchronization object granting Xenomai tasks a concurrent access to a given number of resources maintained in an internal counter variable. The semaphore is used through the P ("Proberen", from the Dutch "test and decrement") and V ("Verhogen", increment) operations. The P operation waits for a unit to become available from the count, and the V operation releases a resource by incrementing the unit count by one.
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.
int rt_sem_bind | ( | RT_SEM * | sem, |
const char * | name, | ||
RTIME | timeout | ||
) |
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.
name | A valid NULL-terminated name which identifies the semaphore to bind to. |
sem | The address of a semaphore descriptor retrieved by the operation. Contents of this memory is undefined upon failure. |
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. |
Environments:
This service can be called from:
Rescheduling: always unless the request is immediately satisfied or timeout specifies a non-blocking operation.
int rt_sem_broadcast | ( | RT_SEM * | sem | ) |
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.
sem | The descriptor address of the affected semaphore. |
Environments:
This service can be called from:
Rescheduling: possible.
References xnpod_schedule(), and xnsynch_flush().
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 Xenomai will use to store the semaphore-related data. This descriptor must always be valid while the semaphore is active therefore it must be allocated in permanent memory. |
name | An ASCII string standing for the symbolic name of the semaphore. When non-NULL and non-empty, this string is copied to a safe place into the descriptor, and passed to the registry package if enabled for indexing the created semaphore. |
icount | The initial value of the semaphore count. |
mode | The semaphore creation mode. The following flags can be OR'ed into this bitmask, each of them affecting the new semaphore: |
Environments:
This service can be called from:
Rescheduling: possible.
References rt_sem_delete(), xnregistry_enter(), and xnsynch_init().
int rt_sem_delete | ( | RT_SEM * | sem | ) |
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.
sem | The descriptor address of the affected semaphore. |
Environments:
This service can be called from:
Rescheduling: possible.
References xnpod_schedule(), and xnregistry_remove().
Referenced by rt_sem_create().
int rt_sem_inquire | ( | RT_SEM * | sem, |
RT_SEM_INFO * | info | ||
) |
Inquire about a semaphore.
Return various information about the status of a given semaphore.
sem | The descriptor address of the inquired semaphore. |
info | The address of a structure the semaphore information will be written to. |
Environments:
This service can be called from:
Rescheduling: never.
int rt_sem_p | ( | RT_SEM * | sem, |
RTIME | timeout | ||
) |
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.
sem | The descriptor address of the affected semaphore. |
timeout | The number of clock ticks to wait for a semaphore unit to be available (see note). Passing TM_INFINITE causes the caller to block indefinitely until a unit is available. Passing TM_NONBLOCK causes the service to return immediately without waiting if no unit is available. |
Environments:
This service can be called from:
Rescheduling: always unless the request is immediately satisfied or timeout specifies a non-blocking operation.
References pthread_setcanceltype().
int rt_sem_p_until | ( | RT_SEM * | sem, |
RTIME | timeout | ||
) |
Pend on a semaphore (with absolute timeout date).
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.
sem | The descriptor address of the affected semaphore. |
timeout | The absolute date specifying a time limit to wait for a semaphore unit to be available (see note). Passing TM_INFINITE causes the caller to block indefinitely until a unit is available. Passing TM_NONBLOCK causes the service to return immediately without waiting if no unit is available. |
Environments:
This service can be called from:
Rescheduling: always unless the request is immediately satisfied or timeout specifies a non-blocking operation.
References pthread_setcanceltype().
int rt_sem_unbind | ( | RT_SEM * | sem | ) | [inline, static] |
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().
sem | The address of a semaphore descriptor to unbind from. |
This service can be called from:
Rescheduling: never.
int rt_sem_v | ( | RT_SEM * | sem | ) |
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.
sem | The descriptor address of the affected semaphore. |
Environments:
This service can be called from:
Rescheduling: possible.
References xnpod_schedule(), and xnsynch_wakeup_one_sleeper().