NetBurner 3.5.0
PDF Version
 
OS_CRIT Struct 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 release 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.
 
uint8_t LockAndEnter (uint32_t timeoutTicks=WAIT_FOREVER)
 Locks the current task to prevent task switching and claims the critical section.
 
uint8_t Enter (TickTimeout &t)
 Request to Enter/Claim the critical section.
 
uint8_t Enter (uint32_t timeoutTicks=WAIT_FOREVER)
 Request to Enter/Claim the critical section, with a time out parameter.
 
uint8_t EnterNoWait ()
 Request to Enter/Claim the critical section. Does not wait if a critical section is not available.
 
uint8_t Leave ()
 Release the critical section.
 
uint8_t LeaveAndUnlock ()
 Leave/release the critical section and unlock the task.
 
bool UsedFromISR ()
 Check if critical section UsedFromISR flag is set.
 
void SetUseFromISR (bool enableFromISR)
 Set critical section UsedFromISR flag.
 
bool OwnedByCurTask ()
 Check if critical section owned by the current task.
 
uint32_t CurDepth ()
 Returns the critical section depth count.
 

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 release the critical section before continuing execution.

Constructor & Destructor Documentation

◆ OS_CRIT()

OS_CRIT::OS_CRIT ( )
inline

Create and initialize an OS_CRIT object.

See also
Init()

Member Function Documentation

◆ CurDepth()

uint32_t OS_CRIT::CurDepth ( )
inline

Returns the critical section depth count.

Returns
Depth count value

◆ Enter() [1/2]

uint8_t OS_CRIT::Enter ( TickTimeout & t)

Request to Enter/Claim the critical section.

Note
You must call Leave() once for each successful Enter() call to release the critical section so that another task can run it.
Parameters
tThe number of TickTimeout time ticks to wait for the critical section. A timeout of 0 (zero) waits forever.
Return values
OS_NO_ERRIf we were successful in claiming the critical section or if our task owns it
OS_TIMEOUTIf we were unable to claim the section NBRTOS Error Codes
See also
NBRTOS Error Codes, EnterNoWait(), Leave()

◆ Enter() [2/2]

uint8_t OS_CRIT::Enter ( uint32_t timeoutTicks = WAIT_FOREVER)
inline

Request to Enter/Claim the critical section, with a time out parameter.

Note
You must call Leave() once for each successful Enter() call to release the critical section so that another task can run it.
Parameters
timeoutTicksThe number of sytem TimeTicks to wait for the critical section. A timeout of 0 (zero) waits forever.
Return values
OS_NO_ERRIf we were successful in claiming the critical section or if our task owns it
OS_TIMEOUTIf we were unable to claim the section NBRTOS Error Codes
See also
NBRTOS Error Codes, EnterNoWait(), Leave()

◆ EnterNoWait()

uint8_t OS_CRIT::EnterNoWait ( )

Request to Enter/Claim the critical section. Does not wait if a critical section is not available.

Note
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_ERRIf we were successful in claiming the critical section or if our task owns it
OS_TIMEOUTIf we were unable to claim the section NBRTOS Error Codes
See also
NBRTOS Error Codes, Enter(), Leave()

◆ Init()

uint8_t OS_CRIT::Init ( )

Initialize an OS_CRIT object to its default state.

Returns
OS_NO_ERR if successful, otherwise NBRTOS Error Codes
See also
NBRTOS Error Codes

◆ Leave()

uint8_t OS_CRIT::Leave ( )

Release the critical section.

Note
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_ERRIf we were successful in claiming the critical section or if our task owns it
OS_CRIT_ERRIf we are trying to release a critical section that we do not own NBRTOS Error Codes
See also
NBRTOS Error Codes, Enter(), EnterNoWait()

◆ LeaveAndUnlock()

uint8_t OS_CRIT::LeaveAndUnlock ( )

Leave/release the critical section and unlock the task.

Note
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.
Returns
OS_NO_ERR on success, otherwise NBRTOS Error Codes
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 the critical section.

Note
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
timeoutTicksThe number of TickTimeout time ticks to wait for the critical section. A timeout of 0 (zero) waits forever.
Return values
OS_NO_ERRIf we were successful in claiming the critical section or if our task owns it
OS_TIMEOUTIf we were unable to claim the section
See also
NBRTOS Error Codes, LeaveAndUnlock(), Enter()

◆ SetUseFromISR()

void OS_CRIT::SetUseFromISR ( bool enableFromISR)
inline

Set critical section UsedFromISR flag.

Parameters
enableFromISRSet true to set flag
See also
UsedFromISR()

◆ UsedFromISR()

bool OS_CRIT::UsedFromISR ( )
inline

Check if critical section UsedFromISR flag is set.

See also
SetUseFromISR()

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