WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
atomic.h
浏览该文件的文档.
1/* ----------------------------------------------------------------------------
2 * Copyright (c) Huawei Technologies Co., Ltd. 2013-2020. All rights reserved.
3 * Description: Aarch32 Atomic HeadFile
4 * Author: Huawei LiteOS Team
5 * Create: 2013-01-01
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
14 * to endorse or promote products derived from this software without specific prior written
15 * permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * --------------------------------------------------------------------------- */
28
34#ifndef _ARCH_GENERIC_ATOMIC_H
35#define _ARCH_GENERIC_ATOMIC_H
36
37#include "los_typedef.h"
38#include "los_hwi.h"
39
40#ifdef __cplusplus
41extern "C" {
42#endif /* __cplusplus */
43
44#ifndef LOSCFG_KERNEL_SMP
45
47{
48 return *(volatile INT32 *)v;
49}
50
52{
53 *(volatile INT32 *)v = setVal;
54}
55
57{
58 UINT32 intSave;
59 INT32 val;
60
61 intSave = LOS_IntLock();
62 *v += addVal;
63 val = *v;
64 LOS_IntRestore(intSave);
65
66 return val;
67}
68
70{
71 UINT32 intSave;
72 INT32 val;
73
74 intSave = LOS_IntLock();
75 *v -= subVal;
76 val = *v;
77 LOS_IntRestore(intSave);
78
79 return val;
80}
81
83{
84 UINT32 intSave;
85
86 intSave = LOS_IntLock();
87 *addr += 1;
88 LOS_IntRestore(intSave);
89}
90
92{
93 UINT32 intSave;
94 INT32 val;
95
96 intSave = LOS_IntLock();
97 *addr += 1;
98 val = *addr;
99 LOS_IntRestore(intSave);
100 return val;
101}
102
104{
105 UINT32 intSave;
106
107 intSave = LOS_IntLock();
108 *addr -= 1;
109 LOS_IntRestore(intSave);
110}
111
113{
114 UINT32 intSave;
115 INT32 val;
116
117 intSave = LOS_IntLock();
118 *addr -= 1;
119 val = *addr;
120 LOS_IntRestore(intSave);
121 return val;
122}
123
125{
126 UINT32 intSave;
127 INT64 val;
128
129 intSave = LOS_IntLock();
130 val = *v;
131 LOS_IntRestore(intSave);
132
133 return val;
134}
135
137{
138 UINT32 intSave;
139
140 intSave = LOS_IntLock();
141 *v = setVal;
142 LOS_IntRestore(intSave);
143}
144
146{
147 UINT32 intSave;
148 INT64 val;
149
150 intSave = LOS_IntLock();
151 *v += addVal;
152 val = *v;
153 LOS_IntRestore(intSave);
154
155 return val;
156}
157
159{
160 UINT32 intSave;
161 INT64 val;
162
163 intSave = LOS_IntLock();
164 *v -= subVal;
165 val = *v;
166 LOS_IntRestore(intSave);
167
168 return val;
169}
170
172{
173 UINT32 intSave;
174
175 intSave = LOS_IntLock();
176 *v += 1;
177 LOS_IntRestore(intSave);
178}
179
181{
182 UINT32 intSave;
183 INT64 val;
184
185 intSave = LOS_IntLock();
186 *v += 1;
187 val = *v;
188 LOS_IntRestore(intSave);
189
190 return val;
191}
192
194{
195 UINT32 intSave;
196
197 intSave = LOS_IntLock();
198 *v -= 1;
199 LOS_IntRestore(intSave);
200}
201
203{
204 UINT32 intSave;
205 INT64 val;
206
207 intSave = LOS_IntLock();
208 *v -= 1;
209 val = *v;
210 LOS_IntRestore(intSave);
211
212 return val;
213}
214
216{
217 UINT32 intSave;
218 INT32 prevVal;
219
220 intSave = LOS_IntLock();
221 prevVal = *v;
222 *v = val;
223 LOS_IntRestore(intSave);
224
225 return prevVal;
226}
227
229{
230 UINT32 intSave;
231 INT64 prevVal;
232
233 intSave = LOS_IntLock();
234 prevVal = *v;
235 *v = val;
236 LOS_IntRestore(intSave);
237
238 return prevVal;
239}
240
242{
243 UINT32 intSave;
244 INT32 prevVal;
245
246 intSave = LOS_IntLock();
247 prevVal = *v;
248 if (prevVal == oldVal) {
249 *v = val;
250 }
251 LOS_IntRestore(intSave);
252
253 return (prevVal != oldVal);
254}
255
257{
258 UINT32 intSave;
259 INT64 prevVal;
260
261 intSave = LOS_IntLock();
262 prevVal = *v;
263 if (prevVal == oldVal) {
264 *v = val;
265 }
266 LOS_IntRestore(intSave);
267
268 return (prevVal != oldVal);
269}
270
271#else
272#error "Generic atomic implementation is not supported on SMP!"
273#endif
274
275#ifdef __cplusplus
276}
277#endif /* __cplusplus */
278
279#endif /* _ARCH_GENERIC_ATOMIC_H */
280
STATIC INLINE BOOL ArchAtomicCmpXchg64bits(Atomic64 *v, INT64 val, INT64 oldVal)
Definition atomic.h:256
STATIC INLINE INT64 ArchAtomic64Read(const Atomic64 *v)
Definition atomic.h:124
STATIC INLINE VOID ArchAtomic64Dec(Atomic64 *v)
Definition atomic.h:193
STATIC INLINE VOID ArchAtomicSet(Atomic *v, INT32 setVal)
Definition atomic.h:51
STATIC INLINE INT64 ArchAtomic64Sub(Atomic64 *v, INT64 subVal)
Definition atomic.h:158
STATIC INLINE INT64 ArchAtomic64IncRet(Atomic64 *v)
Definition atomic.h:180
STATIC INLINE VOID ArchAtomicInc(Atomic *addr)
Definition atomic.h:82
STATIC INLINE INT32 ArchAtomicIncRet(Atomic *addr)
Definition atomic.h:91
STATIC INLINE VOID ArchAtomic64Inc(Atomic64 *v)
Definition atomic.h:171
STATIC INLINE INT32 ArchAtomicXchg32bits(Atomic *v, INT32 val)
Definition atomic.h:215
STATIC INLINE INT32 ArchAtomicDecRet(Atomic *addr)
Definition atomic.h:112
STATIC INLINE INT64 ArchAtomic64DecRet(Atomic64 *v)
Definition atomic.h:202
STATIC INLINE VOID ArchAtomic64Set(Atomic64 *v, INT64 setVal)
Definition atomic.h:136
STATIC INLINE BOOL ArchAtomicCmpXchg32bits(Atomic *v, INT32 val, INT32 oldVal)
Definition atomic.h:241
STATIC INLINE INT64 ArchAtomic64Add(Atomic64 *v, INT64 addVal)
Definition atomic.h:145
STATIC INLINE INT64 ArchAtomicXchg64bits(Atomic64 *v, INT64 val)
Definition atomic.h:228
STATIC INLINE INT32 ArchAtomicSub(Atomic *v, INT32 subVal)
Definition atomic.h:69
STATIC INLINE VOID ArchAtomicDec(Atomic *addr)
Definition atomic.h:103
STATIC INLINE INT32 ArchAtomicRead(const Atomic *v)
Definition atomic.h:46
STATIC INLINE INT32 ArchAtomicAdd(Atomic *v, INT32 addVal)
Definition atomic.h:56
#define STATIC
Definition common_def.h:57
#define INLINE
Definition common_def.h:65
signed int INT32
Definition los_typedef.h:55
volatile INT64 Atomic64
Definition los_typedef.h:86
#define VOID
Definition los_typedef.h:88
volatile INT32 Atomic
Definition los_typedef.h:85
unsigned int UINT32
Definition los_typedef.h:52
size_t BOOL
Definition los_typedef.h:83
signed long long INT64
Definition los_typedef.h:73