ChibiOS/RT  6.0.3
chbsem.h File Reference

Binary semaphores structures and macros. More...

Go to the source code of this file.

Data Structures

struct  ch_binary_semaphore
 Binary semaphore type. More...
 

Macros

#define _BSEMAPHORE_DATA(name, taken)   {_SEMAPHORE_DATA(name.sem, ((taken) ? 0 : 1))}
 Data part of a static semaphore initializer. More...
 
#define BSEMAPHORE_DECL(name, taken)   binary_semaphore_t name = _BSEMAPHORE_DATA(name, taken)
 Static semaphore initializer. More...
 

Typedefs

typedef struct ch_binary_semaphore binary_semaphore_t
 Binary semaphore type. More...
 

Functions

static void chBSemObjectInit (binary_semaphore_t *bsp, bool taken)
 Initializes a binary semaphore. More...
 
static msg_t chBSemWait (binary_semaphore_t *bsp)
 Wait operation on the binary semaphore. More...
 
static msg_t chBSemWaitS (binary_semaphore_t *bsp)
 Wait operation on the binary semaphore. More...
 
static msg_t chBSemWaitTimeoutS (binary_semaphore_t *bsp, sysinterval_t timeout)
 Wait operation on the binary semaphore. More...
 
static msg_t chBSemWaitTimeout (binary_semaphore_t *bsp, sysinterval_t timeout)
 Wait operation on the binary semaphore. More...
 
static void chBSemResetI (binary_semaphore_t *bsp, bool taken)
 Reset operation on the binary semaphore. More...
 
static void chBSemReset (binary_semaphore_t *bsp, bool taken)
 Reset operation on the binary semaphore. More...
 
static void chBSemSignalI (binary_semaphore_t *bsp)
 Performs a signal operation on a binary semaphore. More...
 
static void chBSemSignal (binary_semaphore_t *bsp)
 Performs a signal operation on a binary semaphore. More...
 
static bool chBSemGetStateI (const binary_semaphore_t *bsp)
 Returns the binary semaphore current state. More...
 

Detailed Description

Binary semaphores structures and macros.

Binary semaphores related APIs and services.

Operation mode

Binary semaphores are implemented as a set of inline functions that use the existing counting semaphores primitives. The difference between counting and binary semaphores is that the counter of binary semaphores is not allowed to grow above the value 1. Repeated signal operation are ignored. A binary semaphore can thus have only two defined states:

  • Taken, when its counter has a value of zero or lower than zero. A negative number represent the number of threads queued on the binary semaphore.
  • Not taken, when its counter has a value of one.

Binary semaphores are different from mutexes because there is no concept of ownership, a binary semaphore can be taken by a thread and signaled by another thread or an interrupt handler, mutexes can only be taken and released by the same thread. Another difference is that binary semaphores, unlike mutexes, do not implement the priority inheritance protocol.
In order to use the binary semaphores APIs the CH_CFG_USE_SEMAPHORES option must be enabled in chconf.h.

Definition in file chbsem.h.