ChibiOS/NIL  3.2.2
Binary Semaphores
Collaboration diagram for Binary Semaphores:

Detailed Description

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...
 

Data Structures

struct  ch_binary_semaphore
 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...
 

Macro Definition Documentation

#define _BSEMAPHORE_DATA (   name,
  taken 
)    {_SEMAPHORE_DATA(name.sem, ((taken) ? 0 : 1))}

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.

#define BSEMAPHORE_DECL (   name,
  taken 
)    binary_semaphore_t name = _BSEMAPHORE_DATA(name, taken)

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 type.

Function Documentation

static 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:Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 124 of file chbsem.h.

References chSemObjectInit.

static 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 bsemReset().
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.

static 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 bsemReset().
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(), and chSemWaitS.

Here is the call graph for this function:

static 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 bsemReset().
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(), and chSemWaitTimeoutS().

Here is the call graph for this function:

static 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 bsemReset().
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().

Here is the call graph for this function:

static 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 bsemWait() 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(), and chSemResetI().

Here is the call graph for this function:

static 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 bsemWait() 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().

Here is the call graph for this function:

static 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(), and nil_threads_queue::cnt.

Referenced by chBSemSignal().

Here is the call graph for this function:

static 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:

static 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(), and nil_threads_queue::cnt.

Here is the call graph for this function: