Mbed OS Reference
Loading...
Searching...
No Matches
CriticalSectionLock Class Reference

RAII object for disabling, then restoring, interrupt state Usage: More...

#include <CriticalSectionLock.h>

Static Public Member Functions

static void enable ()
 Mark the start of a critical section. More...
 
static void disable ()
 Mark the end of a critical section. More...
 

Detailed Description

RAII object for disabling, then restoring, interrupt state Usage:

// RAII style usage
unsigned int atomic_counter_increment(unsigned int &counter) {
// Code in this block will run with interrupts disabled
// Interrupts will be restored to their previous state automatically
// at the end of function scope
return ++counter;
}
// free locking usage
unsigned int atomic_counter_decrement(unsigned int &counter) {
// Code in this block will run with interrupts disabled
counter--;
CriticalSectionLock::disable(); // need explicitly to disable critical section lock
// interrupts will be restored to their previous state here
return counter;
}
RAII object for disabling, then restoring, interrupt state Usage:
static void disable()
Mark the end of a critical section.
static void enable()
Mark the start of a critical section.

Definition at line 56 of file CriticalSectionLock.h.

Member Function Documentation

◆ enable()

static void enable ( )
static

Mark the start of a critical section.

◆ disable()

static void disable ( )
static

Mark the end of a critical section.