BeRTOS
Mutually exclusive semaphores
Kernel facilities

Mutually exclusive semaphores. More...

Process synchronization services

void sem_init (struct Semaphore *s)
 Initialize a Semaphore structure.
bool sem_attempt (struct Semaphore *s)
 Attempt to lock a semaphore without waiting.
void sem_obtain (struct Semaphore *s)
 Lock a semaphore.
void sem_release (struct Semaphore *s)
 Release a lock on a previously locked semaphore.

Detailed Description

Mutually exclusive semaphores.

Shared locking not supported in this implementation.

Author:
Bernie Innocenti <bernie@codewiz.org>

Function Documentation

bool sem_attempt ( struct Semaphore *  s)

Attempt to lock a semaphore without waiting.

Returns:
true in case of success, false if the semaphore was already locked by someone else.
Note:
each call to sem_attempt() must be matched by a call to sem_release().
See also:
sem_obtain() sem_release()

Definition at line 78 of file sem.c.

void sem_obtain ( struct Semaphore *  s)

Lock a semaphore.

If the semaphore is already owned by another process, the caller process will be enqueued into the waiting list and sleep until the semaphore is available.

Note:
Each call to sem_obtain() must be matched by a call to sem_release().
This routine is optimized for highest speed in the most common case: the semaphore is free or locked by the calling process itself. Rearranging this code is probably a bad idea.
See also:
sem_release() sem_attempt()

Definition at line 113 of file sem.c.

void sem_release ( struct Semaphore *  s)

Release a lock on a previously locked semaphore.

If the nesting count of the semaphore reaches zero, the next process waiting for it will be awaken.

Note:
This routine is optimized for highest speed in the most common case: the semaphore has been locked just once and nobody else was waiting for it. Rearranging this code is probably a bad idea.
See also:
sem_obtain() sem_attempt()

Definition at line 157 of file sem.c.