Loading...
Searching...
No Matches
sema_inv.h File Reference

Inverse Semaphore definitions. More...

Detailed Description

Inverse Semaphore definitions.

     Inverse Semaphores can be used to synchronize on multiple
     threads / objects.

     The inverse semaphore can be used eiher in counter or in
     mask mode.

     ### Counter Mode ###

     In this mode the inverse Semaphore is initialized with a
     counter variable `n`.
     After `n` calls to @ref sema_inv_post, the waiting thread
     is unblocked.

     ### Mask Mode ###

     In this mode the inverse Semaphore is initialized with a
     bit mask `n`.
     A call to @ref sema_inv_post_mask clears one or multiple bits.
     Clearing the same bit multiple times has no effect.
     The thread is unblocked if all bits have been cleared.
Author
Benjamin Valentin benja.nosp@m.min..nosp@m.valen.nosp@m.tin@.nosp@m.ml-pa.nosp@m..com

Definition in file sema_inv.h.

#include "atomic_utils.h"
#include "mutex.h"
+ Include dependency graph for sema_inv.h:

Go to the source code of this file.

Data Structures

struct  sema_inv_t
 An Inverse Semaphore. More...
 

Functions

bool sema_inv_post (sema_inv_t *s)
 Signal semaphore (counter mode).
 
bool sema_inv_post_mask (sema_inv_t *s, uint32_t mask)
 Signal semaphore (mask mode).
 
static void sema_inv_init (sema_inv_t *s, uint32_t value)
 Initialize an inverse semaphore.
 
static void sema_inv_wait (sema_inv_t *s)
 Wait for the inverse semaphore value to reach zero.
 
static int sema_inv_try_wait (sema_inv_t *s)
 Check if the inverse semaphore value has reached zero.
 
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.