NetBurner 3.5.7
PDF Version
OSLockObj Class Reference

RAII wrapper for OSLock()/OSUnlock() that prevents task switching within a scope. More...

#include <nbrtos.h>

Public Member Functions

 OSLockObj ()
 Construct the OSLockObj and call OSLock() to prevent task switching.
 
 ~OSLockObj ()
 Destruct the OSLockObj and call OSUnlock() to allow task switching.
 

Detailed Description

RAII wrapper for OSLock()/OSUnlock() that prevents task switching within a scope.

The constructor calls OSLock() and the destructor calls OSUnlock(), ensuring the lock is always released when the object goes out of scope, even if the function has multiple return paths or an exception occurs.

Warning
Do not hold the lock for extended periods or perform blocking I/O while locked, as this will degrade network subsystem performance and may cause packet loss.
See also
OSLock(), OSUnlock(), OSCriticalSectionObj

Expand for Example Usage

Examples

Protect a Short Code Sequence
void UpdateGlobalCounter()
{
OSLockObj lock; // Task switching is disabled
gCounter++;
gTimestamp = TimeTick;
} // OSUnlock() is called automatically
RAII wrapper for OSLock()/OSUnlock() that prevents task switching within a scope.
Definition nbrtos.h:2977
volatile tick_t TimeTick
Number of system timer ticks elapsed since system start.


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