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
54#ifndef _STK_UNDER_TEST
55 final
56#endif
57 : public IMutex
58{
59 friend class Event;
60 template <typename T> friend class EventFlagsT;
61 friend class Mutex;
62 friend class FastMutex;
63 friend class RWMutex;
64 template <typename T> friend class SemaphoreT;
65 friend class Pipe;
66 template <typename T, size_t N> friend class PipeT;
67
68public:
71 explicit ScopedCriticalSection() : m_ses(hw::CriticalSection::DEFAULT_SESSION)
72 {
73 Lock();
74 }
75
83
84protected:
86
87 void Lock() override
88 {
90 }
91
92 bool TryLock() override
93 {
94 Lock();
95 return true;
96 }
97
98 void Unlock() override
99 {
101 }
102
104};
105
106} // namespace sync
107} // namespace stk
108
109#endif /* STK_SYNC_CS_H_ */
#define STK_VIRT_DTOR
Expands to nothing if STK_STRICT_COMPLIANCY=0 (non-virtual destructors, smaller objects),...
Definition stk_defs.h:254
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:472
static void Exit(const Session ses=DEFAULT_SESSION)
Exit a critical section.
Interface for mutex synchronization primitive.
Definition stk_common.h:817
ScopedCriticalSection()
Enters critical section.
Definition stk_sync_cs.h:71
bool TryLock() override
Try locking the mutex in a single non-blocking attempt.
Definition stk_sync_cs.h:92
hw::CriticalSection::Session m_ses
current session of hw::CriticalSection
STK_VIRT_DTOR ~ScopedCriticalSection()
Exits critical section.
Definition stk_sync_cs.h:79
void Unlock() override
Unlock the mutex.
Definition stk_sync_cs.h:98
void Lock() override
Lock the mutex.
Definition stk_sync_cs.h:87
STK_NONCOPYABLE_CLASS(ScopedCriticalSection)