NetBurner 3.5.7
PDF Version
OSCriticalSectionObj Class Reference

RAII wrapper for OS_CRIT that automatically enters and leaves a critical section. More...

#include <nbrtos.h>

Public Member Functions

 OSCriticalSectionObj (OS_CRIT &ocrit)
 Construct the object and enter the critical section, waiting indefinitely.
 
 OSCriticalSectionObj (OS_CRIT &ocrit, bool NoWait, TickTimeout &timeout)
 Construct the object and enter the critical section with configurable wait behavior.
 
 ~OSCriticalSectionObj ()
 Destruct the object and call Leave() on the OS_CRIT to release the critical section.
 

Detailed Description

RAII wrapper for OS_CRIT that automatically enters and leaves a critical section.

On construction, calls Enter() on the provided OS_CRIT object (waiting indefinitely by default). On destruction, calls Leave() to release the critical section. This guarantees the section is released regardless of how the enclosing scope is exited.

See also
OS_CRIT::Enter(), OS_CRIT::Leave(), OSLockAndCritObj, OSSpinCrit

Expand for Example Usage

Examples

Protect a Shared Resource
OS_CRIT gCrit;
void AccessSharedData()
{
OSCriticalSectionObj critObj(gCrit);
// Critical section is held for the lifetime of critObj
// ... safely access shared data ...
} // Leave() is called automatically when critObj goes out of scope
RAII wrapper for OS_CRIT that automatically enters and leaves a critical section.
Definition nbrtos.h:3022
Mutual-exclusion critical section for protecting shared resources between tasks.
Definition nbrtos.h:1391

Constructor & Destructor Documentation

◆ OSCriticalSectionObj() [1/2]

OSCriticalSectionObj::OSCriticalSectionObj ( OS_CRIT & ocrit)
inline

Construct the object and enter the critical section, waiting indefinitely.

Parameters
ocritReference to the OS_CRIT object to enter.

◆ OSCriticalSectionObj() [2/2]

OSCriticalSectionObj::OSCriticalSectionObj ( OS_CRIT & ocrit,
bool NoWait,
TickTimeout & timeout )
inline

Construct the object and enter the critical section with configurable wait behavior.

Parameters
ocritReference to the OS_CRIT object to enter.
NoWaitIf true, attempts to enter without waiting (EnterNoWait()). If false, waits up to the specified timeout.
timeoutThe TickTimeout duration to wait when NoWait is false.

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