NetBurner 3.3.8a
PDF Version
OS_CRIT Class Reference

An OS_CRIT object is used to establish critical sections of code that can only be run by one task at a time. Tasks that try to claim a critical section which is currently claimed by another task will stop and wait for that task to leave the critical section before continuing execution. More...

#include <nbrtos.h>

Inherits OS_TASK_DLY_OBJ.

Public Member Functions

 OS_CRIT ()
 Create and initialize an OS_CRIT object.
 
uint8_t Init ()
 Initialize an OS_CRIT object to its default state. More...
 
uint8_t LockAndEnter (uint32_t timeoutTicks=WAIT_FOREVER)
 Locks the current task to prevent task switching, and claims a critical section. More...
 
uint8_t Enter (uint32_t timeoutTicks=WAIT_FOREVER)
 This function tries to enter or claim the critical section. More...
 
uint8_t EnterNoWait ()
 This function tries to enter or claim the critical section. However, this function does not wait if it is unable to enter or claim the critical section. More...
 
uint8_t Leave ()
 This function releases the critical section. More...
 
uint8_t LeaveAndUnlock ()
 This function unlocks the task and releases the critical section. More...
 

Friends

void ForceReboot (bool fromIRQ)
 Forces the system hardware to perform a soft reset.
 

Detailed Description

An OS_CRIT object is used to establish critical sections of code that can only be run by one task at a time. Tasks that try to claim a critical section which is currently claimed by another task will stop and wait for that task to leave the critical section before continuing execution.

Member Function Documentation

◆ Enter()

uint8_t OS_CRIT::Enter ( uint32_t  timeoutTicks = WAIT_FOREVER)

This function tries to enter or claim the critical section.

Important: You must call Leave() once for each successful Enter() call to release the critical section so that another task can run it.

Parameters
timeoutTicksHow many time ticks do we want to wait for this critical section? Note: A timeout of 0 (zero) waits forever.
Return values
OS_NO_ERR- If we were successful in claiming the critical section or if our task owns it
OS_TIMEOUT- If we were unable to claim the section
See also
NBRTOS Error Codes
EnterNoWait()
Leave()

◆ EnterNoWait()

uint8_t OS_CRIT::EnterNoWait ( )

This function tries to enter or claim the critical section. However, this function does not wait if it is unable to enter or claim the critical section.

Important: You must call Leave() once for each successful Enter() call to release the critical section so that another task can run it.

Return values
OS_NO_ERR- If we were successful in claiming the critical section or if our task owns it
OS_TIMEOUT- If we were unable to claim the section
See also
NBRTOS Error Codes
Enter()
Leave()

◆ Init()

uint8_t OS_CRIT::Init ( )

Initialize an OS_CRIT object to its default state.

Return values
OS_NO_ERR- If successful
See also
NBRTOS Error Codes

◆ Leave()

uint8_t OS_CRIT::Leave ( )

This function releases the critical section.

Important: This function must be called once for each successful Enter() or EnterNoWait() call to release the critical section so another task can run it.

Return values
OS_NO_ERR- If we were successful in releasing the critical section
OS_CRIT_ERR- If we are trying to release a critical section that we do not own
See also
NBRTOS Error Codes
Enter()
EnterNoWait()

◆ LeaveAndUnlock()

uint8_t OS_CRIT::LeaveAndUnlock ( )

This function unlocks the task and releases the critical section.

Important: This function must be called once for each successful LockAndEnter() call to both unlock and release the critical section so another task can run it.

Return values
OS_NO_ERR- If we were successful in releasing the critical section
See also
NBRTOS Error Codes
LockAndEnter()

◆ LockAndEnter()

uint8_t OS_CRIT::LockAndEnter ( uint32_t  timeoutTicks = WAIT_FOREVER)

Locks the current task to prevent task switching, and claims a critical section.

Important:If it is unable to claim the critical section and times out, then the lock will be released. Otherwise LeaveAndUnlock() must be called once for each successful LockAndEnter() call to both unlock and release the critical section so that another task might run it.

Parameters
timeoutTicksHow many time ticks do we want to wait for this critical section? Note: A timeout of 0 (zero) waits forever.
Return values
OS_NO_ERR- If we were successful in claiming the critical section or if our task owns it
OS_TIMEOUT- If we were unable to claim the section
See also
NBRTOS Error Codes
LeaveAndUnlock()
Enter()

The documentation for this class was generated from the following files: