inverse Semaphores

Lightweight inverse semaphore implementation. More...

Detailed Description

Lightweight inverse semaphore implementation.

Files

file  sema_inv.h
 Inverse Semaphore definitions.
 

Data Structures

struct  sema_inv_t
 An Inverse Semaphore. More...
 

Functions

bool sema_inv_post (sema_inv_t *s)
 Signal semaphore (counter mode). More...
 
bool sema_inv_post_mask (sema_inv_t *s, uint32_t mask)
 Signal semaphore (mask mode). More...
 
static void sema_inv_init (sema_inv_t *s, uint32_t value)
 Initialize an inverse semaphore. More...
 
static void sema_inv_wait (sema_inv_t *s)
 Wait for the inverse semaphore value to reach zero. More...
 
static int sema_inv_try_wait (sema_inv_t *s)
 Check if the inverse semaphore value has reached zero. More...
 
static int sema_inv_wait_timeout (sema_inv_t *s, uint32_t us)
 Wait for the inverse semaphore value to reach zero or a timeout being reached. More...
 

Function Documentation

◆ sema_inv_init()

static void sema_inv_init ( sema_inv_t s,
uint32_t  value 
)
inlinestatic

Initialize an inverse semaphore.

Parameters
san inverse semaphore
valuestart value, either a counter or a bit mask

Definition at line 99 of file sema_inv.h.

◆ sema_inv_post()

bool sema_inv_post ( sema_inv_t s)

Signal semaphore (counter mode).

Decrements the semaphore counter by one. If the counter reaches zero, the waiting thread is woken.

Parameters
san inverse semaphore
Return values
<tt>true</tt>the value of the semaphore has reached zero and the waiting thread has been woken
<tt>false</tt>the semaphore has not reached zero yet

◆ sema_inv_post_mask()

bool sema_inv_post_mask ( sema_inv_t s,
uint32_t  mask 
)

Signal semaphore (mask mode).

Clears the bits specified by mask from the semaphore value. If the value reaches zero, the waiting thread is woken.

Parameters
san inverse semaphore
maskbit mask to clear from the semaphore value
Return values
<tt>true</tt>the value of the semaphore has reached zero and the waiting thread has been woken
<tt>false</tt>the semaphore has not reached zero yet

◆ sema_inv_try_wait()

static int sema_inv_try_wait ( sema_inv_t s)
inlinestatic

Check if the inverse semaphore value has reached zero.

Parameters
sAn inverse semaphore.
Returns
1 if the semaphore value has reached zero 0 otherwise

Definition at line 124 of file sema_inv.h.

◆ sema_inv_wait()

static void sema_inv_wait ( sema_inv_t s)
inlinestatic

Wait for the inverse semaphore value to reach zero.

Parameters
sAn inverse semaphore.

Definition at line 111 of file sema_inv.h.

◆ sema_inv_wait_timeout()

static int sema_inv_wait_timeout ( sema_inv_t s,
uint32_t  us 
)
inlinestatic

Wait for the inverse semaphore value to reach zero or a timeout being reached.

Parameters
sAn inverse semaphore.
usTime in microseconds until the semaphore times out.
Returns
0 if the semaphore value has reached zero -1 when the timeout occurred

Definition at line 140 of file sema_inv.h.