RAII-style low-level synchronization primitive for atomic code execution. Used as building brick for other stk::sync classes, consider using hw::CriticalSection::ScopedLock implementation instead.
More...
RAII-style low-level synchronization primitive for atomic code execution. Used as building brick for other stk::sync classes, consider using hw::CriticalSection::ScopedLock implementation instead.
Disables interrupts on caller's CPU core and guards from access by another CPU core in case of multi-core system. Enters a critical section upon construction and exits automatically when the object goes out of scope.
uint32_t g_SharedCounter = 0;
void IncrementCounter() {
{
stk::sync::CriticalSection::ScopedLock __cs;
g_SharedCounter++;
}
}
- Note
- Global Impact: Use with extreme care. This primitive has a global effect on the system by preventing preemption. Long-running code inside a critical section will increase interrupt latency and may cause other tasks to miss their deadlines.
-
Unlike higher-level synchronization primitives, this is always available and does not depend on the KERNEL_SYNC configuration.
-
ISR-safe, the only safe primitive along with hw::CriticalSection for guarding code which can be accessed by ISR or another CPU core.
- See also
- IMutex, hw::CriticalSection
Definition at line 53 of file stk_sync_cs.h.