1570af302Sopenharmony_ci/*
2570af302Sopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd.atomic_
3570af302Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4570af302Sopenharmony_ci * you may not use this file except in compliance with the License.
5570af302Sopenharmony_ci * You may obtain a copy of the License at
6570af302Sopenharmony_ci *
7570af302Sopenharmony_ci *		 http://www.apache.org/licenses/LICENSE-2.0
8570af302Sopenharmony_ci *
9570af302Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10570af302Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11570af302Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12570af302Sopenharmony_ci * See the License for the specific language governing permissions and
13570af302Sopenharmony_ci * limitations under the License.
14570af302Sopenharmony_ci */
15570af302Sopenharmony_ci
16570af302Sopenharmony_ci#ifndef _STDATOMIC_IMPL_H
17570af302Sopenharmony_ci#define _STDATOMIC_IMPL_H
18570af302Sopenharmony_ci
19570af302Sopenharmony_ci#include <stddef.h>
20570af302Sopenharmony_ci#include <stdint.h>
21570af302Sopenharmony_ci
22570af302Sopenharmony_citypedef enum memory_order {
23570af302Sopenharmony_ci	memory_order_relaxed = __ATOMIC_RELAXED,
24570af302Sopenharmony_ci	memory_order_consume = __ATOMIC_CONSUME,
25570af302Sopenharmony_ci	memory_order_acquire = __ATOMIC_ACQUIRE,
26570af302Sopenharmony_ci	memory_order_release = __ATOMIC_RELEASE,
27570af302Sopenharmony_ci	memory_order_acq_rel = __ATOMIC_ACQ_REL,
28570af302Sopenharmony_ci	memory_order_seq_cst = __ATOMIC_SEQ_CST
29570af302Sopenharmony_ci} memory_order;
30570af302Sopenharmony_ci
31570af302Sopenharmony_ci#ifdef __cplusplus
32570af302Sopenharmony_citypedef _Atomic(bool)               atomic_bool;
33570af302Sopenharmony_ci#else
34570af302Sopenharmony_citypedef _Atomic(_Bool)              atomic_bool;
35570af302Sopenharmony_ci#endif
36570af302Sopenharmony_citypedef _Atomic(char)               atomic_char;
37570af302Sopenharmony_citypedef _Atomic(signed char)        atomic_schar;
38570af302Sopenharmony_citypedef _Atomic(unsigned char)      atomic_uchar;
39570af302Sopenharmony_citypedef _Atomic(short)              atomic_short;
40570af302Sopenharmony_citypedef _Atomic(unsigned short)     atomic_ushort;
41570af302Sopenharmony_citypedef _Atomic(int)                atomic_int;
42570af302Sopenharmony_citypedef _Atomic(unsigned int)       atomic_uint;
43570af302Sopenharmony_citypedef _Atomic(long)               atomic_long;
44570af302Sopenharmony_citypedef _Atomic(unsigned long)      atomic_ulong;
45570af302Sopenharmony_citypedef _Atomic(long long)          atomic_llong;
46570af302Sopenharmony_citypedef _Atomic(unsigned long long) atomic_ullong;
47570af302Sopenharmony_citypedef _Atomic(uint_least16_t)     atomic_char16_t;
48570af302Sopenharmony_citypedef _Atomic(uint_least32_t)     atomic_char32_t;
49570af302Sopenharmony_citypedef _Atomic(wchar_t)            atomic_wchar_t;
50570af302Sopenharmony_citypedef _Atomic(int_least8_t)       atomic_int_least8_t;
51570af302Sopenharmony_citypedef _Atomic(uint_least8_t)      atomic_uint_least8_t;
52570af302Sopenharmony_citypedef _Atomic(int_least16_t)      atomic_int_least16_t;
53570af302Sopenharmony_citypedef _Atomic(uint_least16_t)     atomic_uint_least16_t;
54570af302Sopenharmony_citypedef _Atomic(int_least32_t)      atomic_int_least32_t;
55570af302Sopenharmony_citypedef _Atomic(uint_least32_t)     atomic_uint_least32_t;
56570af302Sopenharmony_citypedef _Atomic(int_least64_t)      atomic_int_least64_t;
57570af302Sopenharmony_citypedef _Atomic(uint_least64_t)     atomic_uint_least64_t;
58570af302Sopenharmony_citypedef _Atomic(int_fast8_t)        atomic_int_fast8_t;
59570af302Sopenharmony_citypedef _Atomic(uint_fast8_t)       atomic_uint_fast8_t;
60570af302Sopenharmony_citypedef _Atomic(int_fast16_t)       atomic_int_fast16_t;
61570af302Sopenharmony_citypedef _Atomic(uint_fast16_t)      atomic_uint_fast16_t;
62570af302Sopenharmony_citypedef _Atomic(int_fast32_t)       atomic_int_fast32_t;
63570af302Sopenharmony_citypedef _Atomic(uint_fast32_t)      atomic_uint_fast32_t;
64570af302Sopenharmony_citypedef _Atomic(int_fast64_t)       atomic_int_fast64_t;
65570af302Sopenharmony_citypedef _Atomic(uint_fast64_t)      atomic_uint_fast64_t;
66570af302Sopenharmony_citypedef _Atomic(intptr_t)           atomic_intptr_t;
67570af302Sopenharmony_citypedef _Atomic(uintptr_t)          atomic_uintptr_t;
68570af302Sopenharmony_citypedef _Atomic(size_t)             atomic_size_t;
69570af302Sopenharmony_citypedef _Atomic(ptrdiff_t)          atomic_ptrdiff_t;
70570af302Sopenharmony_citypedef _Atomic(intmax_t)           atomic_intmax_t;
71570af302Sopenharmony_citypedef _Atomic(uintmax_t)          atomic_uintmax_t;
72570af302Sopenharmony_ci
73570af302Sopenharmony_ci#define atomic_store(object, desired) __c11_atomic_store(object, desired, __ATOMIC_SEQ_CST)
74570af302Sopenharmony_ci#define atomic_store_explicit __c11_atomic_store
75570af302Sopenharmony_ci
76570af302Sopenharmony_ci#define atomic_load(object) __c11_atomic_load(object, __ATOMIC_SEQ_CST)
77570af302Sopenharmony_ci#define atomic_load_explicit __c11_atomic_load
78570af302Sopenharmony_ci
79570af302Sopenharmony_ci#define atomic_exchange(object, desired) __c11_atomic_exchange(object, desired, __ATOMIC_SEQ_CST)
80570af302Sopenharmony_ci#define atomic_exchange_explicit __c11_atomic_exchange
81570af302Sopenharmony_ci
82570af302Sopenharmony_ci#define atomic_compare_exchange_strong(object, expected, desired) __c11_atomic_compare_exchange_strong(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
83570af302Sopenharmony_ci#define atomic_compare_exchange_strong_explicit __c11_atomic_compare_exchange_strong
84570af302Sopenharmony_ci
85570af302Sopenharmony_ci#define atomic_compare_exchange_weak(object, expected, desired) __c11_atomic_compare_exchange_weak(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
86570af302Sopenharmony_ci#define atomic_compare_exchange_weak_explicit __c11_atomic_compare_exchange_weak
87570af302Sopenharmony_ci
88570af302Sopenharmony_ci#define atomic_fetch_add(object, operand) __c11_atomic_fetch_add(object, operand, __ATOMIC_SEQ_CST)
89570af302Sopenharmony_ci#define atomic_fetch_add_explicit __c11_atomic_fetch_add
90570af302Sopenharmony_ci
91570af302Sopenharmony_ci#define atomic_fetch_sub(object, operand) __c11_atomic_fetch_sub(object, operand, __ATOMIC_SEQ_CST)
92570af302Sopenharmony_ci#define atomic_fetch_sub_explicit __c11_atomic_fetch_sub
93570af302Sopenharmony_ci
94570af302Sopenharmony_ci#define atomic_fetch_or(object, operand) __c11_atomic_fetch_or(object, operand, __ATOMIC_SEQ_CST)
95570af302Sopenharmony_ci#define atomic_fetch_or_explicit __c11_atomic_fetch_or
96570af302Sopenharmony_ci
97570af302Sopenharmony_ci#define atomic_fetch_xor(object, operand) __c11_atomic_fetch_xor(object, operand, __ATOMIC_SEQ_CST)
98570af302Sopenharmony_ci#define atomic_fetch_xor_explicit __c11_atomic_fetch_xor
99570af302Sopenharmony_ci
100570af302Sopenharmony_ci#define atomic_fetch_and(object, operand) __c11_atomic_fetch_and(object, operand, __ATOMIC_SEQ_CST)
101570af302Sopenharmony_ci#define atomic_fetch_and_explicit __c11_atomic_fetch_and
102570af302Sopenharmony_ci
103570af302Sopenharmony_ci#endif // _STDATOMIC_IMPL_H