• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 Huawei Device Co., Ltd.atomic_
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 #ifndef _STDATOMIC_IMPL_H
17 #define _STDATOMIC_IMPL_H
18 
19 #include <stddef.h>
20 #include <stdint.h>
21 
22 typedef enum memory_order {
23 	memory_order_relaxed = __ATOMIC_RELAXED,
24 	memory_order_consume = __ATOMIC_CONSUME,
25 	memory_order_acquire = __ATOMIC_ACQUIRE,
26 	memory_order_release = __ATOMIC_RELEASE,
27 	memory_order_acq_rel = __ATOMIC_ACQ_REL,
28 	memory_order_seq_cst = __ATOMIC_SEQ_CST
29 } memory_order;
30 
31 #ifdef __cplusplus
32 typedef _Atomic(bool)               atomic_bool;
33 #else
34 typedef _Atomic(_Bool)              atomic_bool;
35 #endif
36 typedef _Atomic(char)               atomic_char;
37 typedef _Atomic(signed char)        atomic_schar;
38 typedef _Atomic(unsigned char)      atomic_uchar;
39 typedef _Atomic(short)              atomic_short;
40 typedef _Atomic(unsigned short)     atomic_ushort;
41 typedef _Atomic(int)                atomic_int;
42 typedef _Atomic(unsigned int)       atomic_uint;
43 typedef _Atomic(long)               atomic_long;
44 typedef _Atomic(unsigned long)      atomic_ulong;
45 typedef _Atomic(long long)          atomic_llong;
46 typedef _Atomic(unsigned long long) atomic_ullong;
47 typedef _Atomic(uint_least16_t)     atomic_char16_t;
48 typedef _Atomic(uint_least32_t)     atomic_char32_t;
49 typedef _Atomic(wchar_t)            atomic_wchar_t;
50 typedef _Atomic(int_least8_t)       atomic_int_least8_t;
51 typedef _Atomic(uint_least8_t)      atomic_uint_least8_t;
52 typedef _Atomic(int_least16_t)      atomic_int_least16_t;
53 typedef _Atomic(uint_least16_t)     atomic_uint_least16_t;
54 typedef _Atomic(int_least32_t)      atomic_int_least32_t;
55 typedef _Atomic(uint_least32_t)     atomic_uint_least32_t;
56 typedef _Atomic(int_least64_t)      atomic_int_least64_t;
57 typedef _Atomic(uint_least64_t)     atomic_uint_least64_t;
58 typedef _Atomic(int_fast8_t)        atomic_int_fast8_t;
59 typedef _Atomic(uint_fast8_t)       atomic_uint_fast8_t;
60 typedef _Atomic(int_fast16_t)       atomic_int_fast16_t;
61 typedef _Atomic(uint_fast16_t)      atomic_uint_fast16_t;
62 typedef _Atomic(int_fast32_t)       atomic_int_fast32_t;
63 typedef _Atomic(uint_fast32_t)      atomic_uint_fast32_t;
64 typedef _Atomic(int_fast64_t)       atomic_int_fast64_t;
65 typedef _Atomic(uint_fast64_t)      atomic_uint_fast64_t;
66 typedef _Atomic(intptr_t)           atomic_intptr_t;
67 typedef _Atomic(uintptr_t)          atomic_uintptr_t;
68 typedef _Atomic(size_t)             atomic_size_t;
69 typedef _Atomic(ptrdiff_t)          atomic_ptrdiff_t;
70 typedef _Atomic(intmax_t)           atomic_intmax_t;
71 typedef _Atomic(uintmax_t)          atomic_uintmax_t;
72 
73 #define atomic_store(object, desired) __c11_atomic_store(object, desired, __ATOMIC_SEQ_CST)
74 #define atomic_store_explicit __c11_atomic_store
75 
76 #define atomic_load(object) __c11_atomic_load(object, __ATOMIC_SEQ_CST)
77 #define atomic_load_explicit __c11_atomic_load
78 
79 #define atomic_exchange(object, desired) __c11_atomic_exchange(object, desired, __ATOMIC_SEQ_CST)
80 #define atomic_exchange_explicit __c11_atomic_exchange
81 
82 #define atomic_compare_exchange_strong(object, expected, desired) __c11_atomic_compare_exchange_strong(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
83 #define atomic_compare_exchange_strong_explicit __c11_atomic_compare_exchange_strong
84 
85 #define atomic_compare_exchange_weak(object, expected, desired) __c11_atomic_compare_exchange_weak(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
86 #define atomic_compare_exchange_weak_explicit __c11_atomic_compare_exchange_weak
87 
88 #define atomic_fetch_add(object, operand) __c11_atomic_fetch_add(object, operand, __ATOMIC_SEQ_CST)
89 #define atomic_fetch_add_explicit __c11_atomic_fetch_add
90 
91 #define atomic_fetch_sub(object, operand) __c11_atomic_fetch_sub(object, operand, __ATOMIC_SEQ_CST)
92 #define atomic_fetch_sub_explicit __c11_atomic_fetch_sub
93 
94 #define atomic_fetch_or(object, operand) __c11_atomic_fetch_or(object, operand, __ATOMIC_SEQ_CST)
95 #define atomic_fetch_or_explicit __c11_atomic_fetch_or
96 
97 #define atomic_fetch_xor(object, operand) __c11_atomic_fetch_xor(object, operand, __ATOMIC_SEQ_CST)
98 #define atomic_fetch_xor_explicit __c11_atomic_fetch_xor
99 
100 #define atomic_fetch_and(object, operand) __c11_atomic_fetch_and(object, operand, __ATOMIC_SEQ_CST)
101 #define atomic_fetch_and_explicit __c11_atomic_fetch_and
102 
103 #endif // _STDATOMIC_IMPL_H