• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /**
16  * @defgroup atomic Atomic
17  * @ingroup linux
18  */
19 
20 #ifndef _ASM_ATOMIC_H
21 #define _ASM_ATOMIC_H
22 
23 #include "los_atomic.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif /* __cplusplus */
28 
29 typedef Atomic atomic_t;
30 typedef Atomic64 atomic64_t;
31 
32 /**
33  * @ingroup  atomic
34  * @brief Atomic init.
35  *
36  * @par Description:
37  * This API is used to initialize the atomic variable based on the value of #x.
38  * @attention
39  * None.
40  *
41  * @param  x      [IN] The value to be set.
42  *
43  * @retval None.
44  * @par Dependency:
45  * <ul><li>atomic.h: the header file that contains the API declaration.</li></ul>
46  * @see None.
47  */
48 #define ATOMIC_INIT(x)                  (x)
49 
50 /**
51  * @ingroup  atomic
52  * @brief It is same with #LOS_AtomicRead.
53  * @par Dependency:
54  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
55  */
56 #define atomic_read(v)                  LOS_AtomicRead(v)
57 
58 /**
59  * @ingroup  atomic
60  * @brief It is same with #LOS_AtomicSet.
61  * @par Dependency:
62  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
63  */
64 #define atomic_set(v, i)                LOS_AtomicSet(v, i)
65 
66 /**
67  * @ingroup  atomic
68  * @brief It is same with #LOS_AtomicInc.
69  * @par Dependency:
70  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
71  */
72 #define atomic_inc(v)                   LOS_AtomicInc(v)
73 
74 /**
75  * @ingroup  atomic
76  * @brief It is same with #LOS_AtomicDec.
77  * @par Dependency:
78  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
79  */
80 #define atomic_dec(v)                   LOS_AtomicDec(v)
81 
82 /**
83  * @ingroup  atomic
84  * @brief It is same with #LOS_AtomicAdd.
85  * @attention
86  * <ul>
87  * <li>The parameters of this API comply with Linux, but the input parameter sequence
88  * is different from that of Linux.</li>
89  * </ul>
90  * @par Dependency:
91  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
92  */
93 #define atomic_add(i, v)                LOS_AtomicAdd(v, i)
94 
95 /**
96  * @ingroup  atomic
97  * @brief It is same with #LOS_AtomicSub.
98  * @attention
99  * <ul>
100  * <li>The parameters of this API comply with Linux, but the input parameter sequence
101  * is different from that of Linux.</li>
102  * @par Dependency:
103  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
104  */
105 #define atomic_sub(i, v)                LOS_AtomicSub(v, i)
106 
107 /**
108  * @ingroup  atomic
109  * @brief It is same with #LOS_AtomicAdd.
110  * @attention
111  * <ul>
112  * <li>The parameters of this API comply with Linux, but the input parameter sequence
113  * is different from that of Linux.</li>
114  * @par Dependency:
115  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
116  */
117 #define atomic_add_return(i, v)         LOS_AtomicAdd(v, i)
118 
119 /**
120  * @ingroup  atomic
121  * @brief It is same with #LOS_AtomicIncRet.
122  * @par Dependency:
123  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
124  */
125 #define atomic_inc_return(v)            LOS_AtomicIncRet(v)
126 
127 /**
128  * @ingroup  atomic
129  * @brief It is same with #LOS_AtomicDecRet.
130  * @par Dependency:
131  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
132  */
133 #define atomic_dec_return(v)            LOS_AtomicDecRet(v)
134 #define atomic_dec_and_test(v)          (atomic_dec_return(v) == 0)
135 
136 /**
137  * @ingroup  atomic
138  * @brief Atomic init.
139  *
140  * @par Description:
141  * This API is used to initialize the atomic variable based on the value of #x.
142  * @attention
143  * None.
144  *
145  * @param  x      [IN] The value to be set.
146  *
147  * @retval None.
148  * @par Dependency:
149  * <ul><li>atomic.h: the header file that contains the API declaration.</li></ul>
150  * @see None.
151  */
152 #define ATOMIC64_INIT(x)                (x)
153 
154 /**
155  * @ingroup  atomic
156  * @brief It is same with #LOS_Atomic64Read.
157  * @par Dependency:
158  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
159  */
160 #define atomic64_read(v)                LOS_Atomic64Read(v)
161 
162 /**
163  * @ingroup  atomic
164  * @brief It is same with #LOS_Atomic64Set.
165  * @par Dependency:
166  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
167  */
168 #define atomic64_set(v, i)              LOS_Atomic64Set(v, i)
169 
170 /**
171  * @ingroup  atomic
172  * @brief It is same with #LOS_Atomic64Inc.
173  * @par Dependency:
174  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
175  */
176 #define atomic64_inc(v)                 LOS_Atomic64Inc(v)
177 
178 /**
179  * @ingroup  atomic
180  * @brief It is same with #LOS_Atomic64Dec.
181  * @par Dependency:
182  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
183  */
184 #define atomic64_dec(v)                 LOS_Atomic64Dec(v)
185 
186 /**
187  * @ingroup  atomic
188  * @brief It is same with #LOS_Atomic64Add.
189  * @attention
190  * <ul>
191  * <li>The parameters of this API comply with Linux, but the input parameter sequence
192  * is different from that of Linux.</li>
193  * @par Dependency:
194  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
195  */
196 #define atomic64_add(i, v)              LOS_Atomic64Add(v, i)
197 
198 /**
199  * @ingroup  atomic
200  * @brief It is same with #LOS_Atomic64Sub.
201  * @attention
202  * <ul>
203  * <li>The parameters of this API comply with Linux, but the input parameter sequence
204  * is different from that of Linux.</li>
205  * @par Dependency:
206  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
207  */
208 #define atomic64_sub(i, v)              LOS_Atomic64Sub(v, i)
209 
210 /**
211  * @ingroup  atomic
212  * @brief It is same with #LOS_Atomic64Add.
213  * @attention
214  * <ul>
215  * <li>The parameters of this API comply with Linux, but the input parameter sequence
216  * is different from that of Linux.</li>
217  * @par Dependency:
218  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
219  */
220 #define atomic64_add_return(i, v)       LOS_Atomic64Add(v, i)
221 
222 /**
223  * @ingroup  atomic
224  * @brief It is same with #LOS_Atomic64IncRet.
225  * @par Dependency:
226  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
227  */
228 #define atomic64_inc_return(v)          LOS_Atomic64IncRet(v)
229 
230 /**
231  * @ingroup  atomic
232  * @brief It is same with #LOS_Atomic64DecRet.
233  * @par Dependency:
234  * <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
235  */
236 #define atomic64_dec_return(v)          LOS_Atomic64DecRet(v)
237 #define atomic64_dec_and_test(v)        (atomic64_dec_return(v) == 0)
238 
239 #ifdef __cplusplus
240 }
241 #endif /* __cplusplus */
242 
243 #endif /* _ASM_ATOMIC_H */
244