StateOS
Toggle main menu visibility
Loading...
Searching...
No Matches
oscriticalsection.h
1
/******************************************************************************
2
3
@file StateOS: oscriticalsection.h
4
@author Rajmund Szymanski
5
@date 17.11.2025
6
@brief This file contains definitions for StateOS.
7
8
******************************************************************************
9
10
Copyright (c) 2018-2022 Rajmund Szymanski. All rights reserved.
11
12
Permission is hereby granted, free of charge, to any person obtaining a copy
13
of this software and associated documentation files (the "Software"), to
14
deal in the Software without restriction, including without limitation the
15
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16
sell copies of the Software, and to permit persons to whom the Software is
17
furnished to do so, subject to the following conditions:
18
19
The above copyright notice and this permission notice shall be included
20
in all copies or substantial portions of the Software.
21
22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28
IN THE SOFTWARE.
29
30
******************************************************************************/
31
32
#ifndef __STATEOS_CRI_H
33
#define __STATEOS_CRI_H
34
35
#include "oskernel.h"
36
42
43
#ifdef __cplusplus
44
extern
"C"
{
45
#endif
46
47
/******************************************************************************
48
*
49
* Name : core_set_lock
50
*
51
* Description : disable interrupts
52
*
53
* Parameters : none
54
*
55
* Return : previous interrupts state
56
*
57
* Note : for internal use
58
*
59
******************************************************************************/
60
61
__STATIC_INLINE
62
lck_t core_set_lock(
void
)
63
{
64
lck_t prv = port_get_lock();
65
port_set_lock();
66
__COMPILER_BARRIER();
67
return
prv;
68
}
69
70
/******************************************************************************
71
*
72
* Name : core_clr_lock
73
*
74
* Description : enable interrupts
75
*
76
* Parameters : none
77
*
78
* Return : previous interrupts state
79
*
80
* Note : for internal use
81
*
82
******************************************************************************/
83
84
__STATIC_INLINE
85
lck_t core_clr_lock(
void
)
86
{
87
lck_t prv = port_get_lock();
88
port_clr_lock();
89
__COMPILER_BARRIER();
90
return
prv;
91
}
92
93
/******************************************************************************
94
*
95
* Name : core_put_lock
96
*
97
* Description : restore interrupts state
98
*
99
* Parameters
100
* lck : interrupts state
101
*
102
* Return : none
103
*
104
* Note : for internal use
105
*
106
******************************************************************************/
107
108
__STATIC_INLINE
109
void
core_put_lock( lck_t lck )
110
{
111
__COMPILER_BARRIER();
112
port_put_lock(lck);
113
}
114
115
/******************************************************************************
116
*
117
* Name : core_get_lock
118
*
119
* Description : return current interrupts state
120
*
121
* Parameters : none
122
*
123
* Return : current interrupts state
124
*
125
* Note : for internal use
126
*
127
******************************************************************************/
128
129
__STATIC_INLINE
130
lck_t core_get_lock(
void
)
131
{
132
return
port_get_lock();
133
}
134
142
143
#define sys_lock() \
144
do { lck_t __LOCK = core_set_lock()
145
147
#define sys_lockISR() \
148
sys_lock()
149
157
158
#define sys_unlock() \
159
core_put_lock(__LOCK); } while (0)
160
162
#define sys_unlockISR() \
163
sys_unlock()
164
165
#ifdef __cplusplus
166
}
167
#endif
168
169
/* -------------------------------------------------------------------------- */
170
171
#if defined(__cplusplus) && (__cplusplus >= 201103L) && !defined(__STATEOS_STDCXX)
172
namespace
stateos {
173
177
178
struct
CriticalSection
179
{
181
CriticalSection
() { lck_ = core_set_lock(); }
182
183
~CriticalSection
() { core_put_lock(lck_); }
184
185
CriticalSection
(
CriticalSection
&& ) =
delete
;
186
CriticalSection
(
const
CriticalSection
& ) =
delete
;
187
CriticalSection
& operator=(
CriticalSection
&& ) =
delete
;
188
CriticalSection
& operator=(
const
CriticalSection
& ) =
delete
;
189
190
private
:
191
lck_t lck_;
192
};
193
194
}
// namespace
195
#endif
//__cplusplus
196
197
/* -------------------------------------------------------------------------- */
198
200
201
#endif
//__STATEOS_CRI_H
stateos::CriticalSection
create and initialize a critical section guard object
Definition
oscriticalsection.h:179
stateos::CriticalSection::CriticalSection
CriticalSection()
constructor, see the constructor parameters of the class
Definition
oscriticalsection.h:181
kernel
inc
oscriticalsection.h
Generated by
1.18.0