Introduction   API Reference   Examples   Index  

Semaphore Usage
[L4 Semaphore API]

L4 Semaphore usage. More...

Defines

#define L4SEMAPHORE_INITIALIZER(x)   {(x), 0, NULL}
 Semaphore initializer, use this to initialize semaphores in nested structures.
#define L4SEMAPHORE_INIT(x)   ((l4semaphore_t)L4SEMAPHORE_INITIALIZER(x))
 Semaphore value generator, use this to initialize plain semaphores.
#define L4SEMAPHORE_LOCKED_INITIALIZER   L4SEMAPHORE_INITIALIZER(0)
 Semaphore initializer, initial count 0 (semaphore locked).
#define L4SEMAPHORE_LOCKED   ((l4semaphore_t)L4SEMAPHORE_LOCKED_INITIALIZER)
 Locked semaphore value, initial count 0.
#define L4SEMAPHORE_UNLOCKED_INITIALIZER   L4SEMAPHORE_INITIALIZER(1)
 Semaphore initializer, initial count 1 (semaphore unlocked).
#define L4SEMAPHORE_UNLOCKED   ((l4semaphore_t)L4SEMAPHORE_UNLOCKED_INITIALIZER)
 Unlocked semaphore value, initial count 1.

Functions

L4_INLINE void l4semaphore_down (l4semaphore_t *sem)
 Decrement semaphore counter, block if result is < 0.
L4_INLINE int l4semaphore_down_timed (l4semaphore_t *sem, unsigned timeout)
 Decrement semaphore counter, block for a given time if result is < 0.
L4_INLINE int l4semaphore_try_down (l4semaphore_t *sem)
 Decrement semaphore counter, do not wait if result is < 0.
L4_INLINE void l4semaphore_up (l4semaphore_t *sem)
 Increment semaphore counter, wakeup next thread in wait queue.

Detailed Description

L4 Semaphore usage.


Define Documentation

#define L4SEMAPHORE_INITIALIZER (  )     {(x), 0, NULL}

Semaphore initializer, use this to initialize semaphores in nested structures.

Parameters:
x Initial value for semaphore counter

Definition at line 73 of file semaphore.h.

#define L4SEMAPHORE_INIT (  )     ((l4semaphore_t)L4SEMAPHORE_INITIALIZER(x))

Semaphore value generator, use this to initialize plain semaphores.

Parameters:
x Initial value for semaphore counter

Definition at line 80 of file semaphore.h.

#define L4SEMAPHORE_LOCKED_INITIALIZER   L4SEMAPHORE_INITIALIZER(0)

Semaphore initializer, initial count 0 (semaphore locked).

Definition at line 87 of file semaphore.h.

#define L4SEMAPHORE_LOCKED   ((l4semaphore_t)L4SEMAPHORE_LOCKED_INITIALIZER)

Locked semaphore value, initial count 0.

Definition at line 94 of file semaphore.h.

#define L4SEMAPHORE_UNLOCKED_INITIALIZER   L4SEMAPHORE_INITIALIZER(1)

Semaphore initializer, initial count 1 (semaphore unlocked).

Definition at line 101 of file semaphore.h.

#define L4SEMAPHORE_UNLOCKED   ((l4semaphore_t)L4SEMAPHORE_UNLOCKED_INITIALIZER)

Unlocked semaphore value, initial count 1.

Definition at line 108 of file semaphore.h.


Function Documentation

L4_INLINE void l4semaphore_down ( l4semaphore_t sem  ) 

Decrement semaphore counter, block if result is < 0.

Parameters:
sem Semaphore structure
Decrement semaphore counter by 1. If the result is < 0, l4semaphore_down blocks and waits for the release of the semaphore.

L4_INLINE int l4semaphore_down_timed ( l4semaphore_t sem,
unsigned  timeout 
)

Decrement semaphore counter, block for a given time if result is < 0.

Parameters:
sem Semaphore structure
timeout Timeout (in ms), timeout must be positive
Returns:
0 if semaphore successfully decremented within given time, != 0 otherwise.
: A timeout of 0 ms means promptly checkin to enter the critical section. If infinitive timeouts are required, use l4semaphore_down instead.

Decrement semaphore counter by 1. If the result is < 0, l4semaphore_down_timed blocks for time ms and waits for the release of the semaphore.

L4_INLINE int l4semaphore_try_down ( l4semaphore_t sem  ) 

Decrement semaphore counter, do not wait if result is < 0.

Parameters:
sem Semaphore structure
Returns:
1 on success (counter decremented), 0 if semaphore already locked
Try to decrement semaphore counter by 1, if the result would be < 0, return error instead.

L4_INLINE void l4semaphore_up ( l4semaphore_t sem  ) 

Increment semaphore counter, wakeup next thread in wait queue.

Parameters:
sem Semaphore structure
Increment semaphore counter by 1. If threads are enqueued in the wait queue, wakeup the first thread.


L4 Semaphore Reference Manual, written by Lars Reuther  © 2000-2003