NetBurner 3.5.0
PDF Version
 
OS_SEM Struct Reference

Semaphores are used to control access to shared resources or or to communicate between tasks in a multithreaded system or with interrupt service routines. Semaphores can be 0 or 1, or they can be counting semaphores that increment and decreement based on calls to Pend() and Post() functions. More...

#include <nbrtos.h>

Inherits OS_TASK_DLY_OBJ.

Public Member Functions

 OS_SEM (int32_t cnt=0)
 Create and initialize a semaphore.
 
uint8_t Init (int32_t cnt=0)
 Initialize the semaphore object count value.
 
uint8_t Post ()
 Posts to the semaphore, increasing it's value by 1.
 
uint8_t Pend (uint32_t timeoutTicks=WAIT_FOREVER)
 Wait timeout ticks for the value of the semaphore to be non zero.
 
uint8_t PendUntil (uint32_t timeout_time)
 Wait until the specified timeout time for a task to post to the semaphore.
 
uint8_t Pend (TickTimeout &t)
 Wait for the specified number of system time ticks for a task to post to the semaphore.
 
uint8_t PendNoWait ()
 Pend on a semaphore with no waiting period.
 
uint32_t Avail ()
 Returns the number of semaphore counts availble.
 

Detailed Description

Semaphores are used to control access to shared resources or or to communicate between tasks in a multithreaded system or with interrupt service routines. Semaphores can be 0 or 1, or they can be counting semaphores that increment and decreement based on calls to Pend() and Post() functions.

Constructor & Destructor Documentation

◆ OS_SEM()

OS_SEM::OS_SEM ( int32_t cnt = 0)
inline

Create and initialize a semaphore.

Parameters
cntStarting semaphore count value. If not specified, default is 0.
See also
Init(int32_t cnt = 0)

Member Function Documentation

◆ Avail()

uint32_t OS_SEM::Avail ( )
inline

Returns the number of semaphore counts availble.

Difference between the number of counts used and the total count value.

Returns
The number of available semaphore counts
See also
Pend(), Post()

◆ Init()

uint8_t OS_SEM::Init ( int32_t cnt = 0)

Initialize the semaphore object count value.

Warning
This must be done before using the semaphore.
Parameters
cntStarting semaphore count value. If not specified, default is 0.
Returns
OS_NO_ERR on success, otherwise NBRTOS Error Codes

◆ Pend() [1/2]

uint8_t OS_SEM::Pend ( TickTimeout & t)

Wait for the specified number of system time ticks for a task to post to the semaphore.

Parameters
tThe number of TickTiemout ticks to wait. A value of 0 will wait forever.
Returns
OS_NO_ERR on success, otherwise NBRTOS Error Codes
See also
PendNoWait(), PendUntil()

◆ Pend() [2/2]

uint8_t OS_SEM::Pend ( uint32_t timeoutTicks = WAIT_FOREVER)
inline

Wait timeout ticks for the value of the semaphore to be non zero.

Parameters
timeoutTicksNumber of system time ticks to wait. If not specified, will wait forever.
Returns
OS_NO_ERR on success, otherwise NBRTOS Error Codes
See also
PendNoWait(), PendUntil()

◆ PendNoWait()

uint8_t OS_SEM::PendNoWait ( )

Pend on a semaphore with no waiting period.

Identical to the Pend() function, but it does not wait.

Returns
OS_NO_ERR on success, otherwise NBRTOS Error Codes
See also
Pend(), PendUntil()

◆ PendUntil()

uint8_t OS_SEM::PendUntil ( uint32_t timeout_time)
inline

Wait until the specified timeout time for a task to post to the semaphore.

Parameters
timeout_timeThe system TimeTick value to wait until
Returns
OS_NO_ERR on success, otherwise NBRTOS Error Codes
See also
PendNoWait(), Pend()

◆ Post()

uint8_t OS_SEM::Post ( )

Posts to the semaphore, increasing it's value by 1.

If a higher priority task was pending on the semaphore it will be released.

Returns
OS_NO_ERR on success, otherwise NBRTOS Error Codes
See also
Pend(), PendUntil(), PendNoWait()

The documentation for this struct was generated from the following file: