Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Atomic Class Reference

Lightweight locking class for protecting small critical sections. More...

#include <Atomic.hxx>

Inheritance diagram for Atomic:
BarrierNotifiable BenchmarkCan BitBangI2C< HW > CC32xxSPI Can DirectHubImpl< T > DynamicPool EepromTimerFlow FdHubPortBase FixedPool GcTcpHub HubDeviceSelect< HFlow, ReadFlow > LimitedPool MCP23017 OSSelectWakeup Pic32mxCdc Q SPIFFS SemaphoreNotifiableBlock ShadowedStoredBitSet SocketClient StateFlowWithQueue TCAN4550Can TCAN4550Can TMAG5273 TimeBase openlcb::BLEHubPort::InputFlow openlcb::BroadcastTimeAlarm openlcb::BroadcastTimeAlarm::Wakeup openlcb::ConfigUpdateFlow openlcb::EventIdentifyGlobal openlcb::RefreshLoop openlcb::TrainService openlcb::TreeEventHandlers openlcb::VectorEventHandlers openmrn_arduino::Esp32HardwareI2C

Public Member Functions

void lock ()
 
void unlock ()
 

Private Attributes

os_mutex_t mu_ = OS_RECURSIVE_MUTEX_INITIALIZER
 Mutex that protects.
 

Detailed Description

Lightweight locking class for protecting small critical sections.

Properties:

  • May be recursively acquired
  • FreeRTOS: No call inside an Atomic-protected section may block
  • FreeRTOS: Not allowed to use from interrupt context. Kernel-compatible ISRs are disabled during an Atomic held.

Under FreeRTOS locking a mutex is more than 2x more expensive than locking an Atomic. On desktop OS's Atomic is just a recursive mutex.

Usage: Declare Atomic as a private base class, add a class member variable or a global variable of type Atomic. Then use AtomicHolder to protect the critical sections.

Definition at line 129 of file Atomic.hxx.

Member Function Documentation

◆ lock()

void Atomic::lock ( )
inline

Definition at line 132 of file Atomic.hxx.

◆ unlock()

void Atomic::unlock ( )
inline

Definition at line 136 of file Atomic.hxx.

Member Data Documentation

◆ mu_

os_mutex_t Atomic::mu_ = OS_RECURSIVE_MUTEX_INITIALIZER
private

Mutex that protects.

NOTE: it is important that this be trivially initialized and the Atomic class have no (nontrivial) constructor. This is the only way to avoid race conditions and initialization order problems during startup.

Definition at line 146 of file Atomic.hxx.


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