ChibiOS 21.11.4
Binary Semaphores

Detailed Description

Collaboration diagram for Binary Semaphores:

Data Structures

struct  ch_binary_semaphore
 Binary semaphore type. More...

Macros

#define __BSEMAPHORE_DATA(name, taken)
 Data part of a static semaphore initializer.
#define BSEMAPHORE_DECL(name, taken)
 Static semaphore initializer.

Typedefs

typedef struct ch_binary_semaphore binary_semaphore_t
 Binary semaphore type.

Functions

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

Macro Definition Documentation

◆ __BSEMAPHORE_DATA

#define __BSEMAPHORE_DATA ( name,
taken )
Value:
{__SEMAPHORE_DATA(name.sem, ((taken) ? 0 : 1))}
#define __SEMAPHORE_DATA(name, n)
Data part of a static semaphore initializer.

Data part of a static semaphore initializer.

This macro should be used when statically initializing a semaphore that is part of a bigger structure.

Parameters
[in]namethe name of the semaphore variable
[in]takenthe semaphore initial state

Definition at line 91 of file chbsem.h.

◆ BSEMAPHORE_DECL

#define BSEMAPHORE_DECL ( name,
taken )
Value:
#define __BSEMAPHORE_DATA(name, taken)
Data part of a static semaphore initializer.
Definition chbsem.h:91
struct ch_binary_semaphore binary_semaphore_t
Binary semaphore type.

Static semaphore initializer.

Statically initialized semaphores require no explicit initialization using chBSemInit().

Parameters
[in]namethe name of the semaphore variable
[in]takenthe semaphore initial state

Definition at line 102 of file chbsem.h.

Typedef Documentation

◆ binary_semaphore_t

Binary semaphore type.

Function Documentation

◆ chBSemObjectInit()

void chBSemObjectInit ( binary_semaphore_t * bsp,
bool taken )
inlinestatic

Initializes a binary semaphore.

Parameters
[out]bsppointer to a binary_semaphore_t structure
[in]takeninitial state of the binary semaphore:
  • false, the initial state is not taken.
  • true, the initial state is taken.
Function Class:
Object or module nitializer function.

Definition at line 124 of file chbsem.h.

References chSemObjectInit, and ch_binary_semaphore::sem.

◆ chBSemWait()

msg_t chBSemWait ( binary_semaphore_t * bsp)
inlinestatic

Wait operation on the binary semaphore.

Parameters
[in]bsppointer to a binary_semaphore_t structure
Returns
A message specifying how the invoking thread has been released from the semaphore.
Return values
MSG_OKif the binary semaphore has been successfully taken.
MSG_RESETif the binary semaphore has been reset using chBSemReset().
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 141 of file chbsem.h.

References chSemWait, and ch_binary_semaphore::sem.

◆ chBSemWaitS()

msg_t chBSemWaitS ( binary_semaphore_t * bsp)
inlinestatic

Wait operation on the binary semaphore.

Parameters
[in]bsppointer to a binary_semaphore_t structure
Returns
A message specifying how the invoking thread has been released from the semaphore.
Return values
MSG_OKif the binary semaphore has been successfully taken.
MSG_RESETif the binary semaphore has been reset using chBSemReset().
Function Class:
This is an S-Class API, this function can be invoked from within a system lock zone by threads only.

Definition at line 158 of file chbsem.h.

References chDbgCheckClassS, chSemWaitS, and ch_binary_semaphore::sem.

◆ chBSemWaitTimeoutS()

msg_t chBSemWaitTimeoutS ( binary_semaphore_t * bsp,
sysinterval_t timeout )
inlinestatic

Wait operation on the binary semaphore.

Parameters
[in]bsppointer to a binary_semaphore_t structure
[in]timeoutthe number of ticks before the operation timeouts, the following special values are allowed:
  • TIME_IMMEDIATE immediate timeout.
  • TIME_INFINITE no timeout.
Returns
A message specifying how the invoking thread has been released from the semaphore.
Return values
MSG_OKif the binary semaphore has been successfully taken.
MSG_RESETif the binary semaphore has been reset using chBSemReset().
MSG_TIMEOUTif the binary semaphore has not been signaled or reset within the specified timeout.
Function Class:
This is an S-Class API, this function can be invoked from within a system lock zone by threads only.

Definition at line 184 of file chbsem.h.

References chDbgCheckClassS, chSemWaitTimeoutS(), and ch_binary_semaphore::sem.

Here is the call graph for this function:

◆ chBSemWaitTimeout()

msg_t chBSemWaitTimeout ( binary_semaphore_t * bsp,
sysinterval_t timeout )
inlinestatic

Wait operation on the binary semaphore.

Parameters
[in]bsppointer to a binary_semaphore_t structure
[in]timeoutthe number of ticks before the operation timeouts, the following special values are allowed:
  • TIME_IMMEDIATE immediate timeout.
  • TIME_INFINITE no timeout.
Returns
A message specifying how the invoking thread has been released from the semaphore.
Return values
MSG_OKif the binary semaphore has been successfully taken.
MSG_RESETif the binary semaphore has been reset using chBSemReset().
MSG_TIMEOUTif the binary semaphore has not been signaled or reset within the specified timeout.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 211 of file chbsem.h.

References chSemWaitTimeout(), and ch_binary_semaphore::sem.

Here is the call graph for this function:

◆ chBSemResetI()

void chBSemResetI ( binary_semaphore_t * bsp,
bool taken )
inlinestatic

Reset operation on the binary semaphore.

Note
The released threads can recognize they were waked up by a reset rather than a signal because the chBSemWait() will return MSG_RESET instead of MSG_OK.
This function does not reschedule.
Parameters
[in]bsppointer to a binary_semaphore_t structure
[in]takennew state of the binary semaphore
  • false, the new state is not taken.
  • true, the new state is taken.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 232 of file chbsem.h.

References chDbgCheckClassI, chSemResetI, and ch_binary_semaphore::sem.

◆ chBSemReset()

void chBSemReset ( binary_semaphore_t * bsp,
bool taken )
inlinestatic

Reset operation on the binary semaphore.

Note
The released threads can recognize they were waked up by a reset rather than a signal because the chBSemWait() will return MSG_RESET instead of MSG_OK.
Parameters
[in]bsppointer to a binary_semaphore_t structure
[in]takennew state of the binary semaphore
  • false, the new state is not taken.
  • true, the new state is taken.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 253 of file chbsem.h.

References chSemReset, and ch_binary_semaphore::sem.

◆ chBSemSignalI()

void chBSemSignalI ( binary_semaphore_t * bsp)
inlinestatic

Performs a signal operation on a binary semaphore.

Note
This function does not reschedule.
Parameters
[in]bsppointer to a binary_semaphore_t structure
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 266 of file chbsem.h.

References chDbgCheckClassI, chSemSignalI(), ch_semaphore::cnt, and ch_binary_semaphore::sem.

Referenced by chBSemSignal().

Here is the call graph for this function:

◆ chBSemSignal()

void chBSemSignal ( binary_semaphore_t * bsp)
inlinestatic

Performs a signal operation on a binary semaphore.

Parameters
[in]bsppointer to a binary_semaphore_t structure
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 282 of file chbsem.h.

References chBSemSignalI(), chSchRescheduleS(), chSysLock, and chSysUnlock.

Here is the call graph for this function:

◆ chBSemGetStateI()

bool chBSemGetStateI ( const binary_semaphore_t * bsp)
inlinestatic

Returns the binary semaphore current state.

Parameters
[in]bsppointer to a binary_semaphore_t structure
Returns
The binary semaphore current state.
Return values
falseif the binary semaphore is not taken.
trueif the binary semaphore is taken.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 300 of file chbsem.h.

References chDbgCheckClassI, ch_semaphore::cnt, and ch_binary_semaphore::sem.