SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk_sync_cs.h
Go to the documentation of this file.
1/*
2 * SuperTinyKernel(TM) RTOS: Lightweight High-Performance Deterministic C++ RTOS for Embedded Systems.
3 *
4 * Source: https://github.com/SuperTinyKernel-RTOS
5 *
6 * Copyright (c) 2022-2026 Neutron Code Limited <stk@neutroncode.com>. All Rights Reserved.
7 * License: MIT License, see LICENSE for a full text.
8 */
9
10#ifndef STK_SYNC_CS_H_
11#define STK_SYNC_CS_H_
12
13#include "stk_helper.h"
14
18
19namespace stk {
20namespace sync {
21
53class ScopedCriticalSection final : public IMutex
54{
55 friend class Event;
56 friend class EventFlags;
57 friend class Mutex;
58 friend class RWMutex;
59 friend class Semaphore;
60 friend class Pipe;
61 template <typename T, size_t N> friend class PipeT;
62
63public:
66 explicit ScopedCriticalSection() : m_ses(hw::CriticalSection::DEFAULT_SESSION)
67 {
68 Lock();
69 }
70
78
79private:
81
82 void Lock() override
83 {
85 }
86
87 void Unlock() override
88 {
90 }
91
93};
94
95} // namespace sync
96} // namespace stk
97
98#endif /* STK_SYNC_CS_H_ */
#define STK_VIRT_DTOR
Makes destructors virtual and compliant to strict rules if STK_STRICT_COMPLIANCY=0.
Definition stk_defs.h:202
Contains helper implementations which simplify user-side code.
Namespace of STK package.
Hardware Abstraction Layer (HAL) for architecture-specific operations.
Synchronization primitives for task coordination and resource protection.
static Session Enter(const Session ses=DEFAULT_SESSION)
Enter a critical section.
uint8_t Session
Opaque session token returned by Enter() and consumed by Exit().
Definition stk_arch.h:363
static void Exit(const Session ses=DEFAULT_SESSION)
Exit a critical section.
Interface for mutex synchronization primitive.
Definition stk_common.h:677
ScopedCriticalSection()
Enters critical section.
Definition stk_sync_cs.h:66
hw::CriticalSection::Session m_ses
current session of hw::CriticalSection
Definition stk_sync_cs.h:92
STK_VIRT_DTOR ~ScopedCriticalSection()
Exits critical section.
Definition stk_sync_cs.h:74
void Unlock() override
Unlock the mutex.
Definition stk_sync_cs.h:87
void Lock() override
Lock the mutex.
Definition stk_sync_cs.h:82
STK_NONCOPYABLE_CLASS(ScopedCriticalSection)