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 22typedef 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 32typedef _Atomic(bool) atomic_bool; 33#else 34typedef _Atomic(_Bool) atomic_bool; 35#endif 36typedef _Atomic(char) atomic_char; 37typedef _Atomic(signed char) atomic_schar; 38typedef _Atomic(unsigned char) atomic_uchar; 39typedef _Atomic(short) atomic_short; 40typedef _Atomic(unsigned short) atomic_ushort; 41typedef _Atomic(int) atomic_int; 42typedef _Atomic(unsigned int) atomic_uint; 43typedef _Atomic(long) atomic_long; 44typedef _Atomic(unsigned long) atomic_ulong; 45typedef _Atomic(long long) atomic_llong; 46typedef _Atomic(unsigned long long) atomic_ullong; 47typedef _Atomic(uint_least16_t) atomic_char16_t; 48typedef _Atomic(uint_least32_t) atomic_char32_t; 49typedef _Atomic(wchar_t) atomic_wchar_t; 50typedef _Atomic(int_least8_t) atomic_int_least8_t; 51typedef _Atomic(uint_least8_t) atomic_uint_least8_t; 52typedef _Atomic(int_least16_t) atomic_int_least16_t; 53typedef _Atomic(uint_least16_t) atomic_uint_least16_t; 54typedef _Atomic(int_least32_t) atomic_int_least32_t; 55typedef _Atomic(uint_least32_t) atomic_uint_least32_t; 56typedef _Atomic(int_least64_t) atomic_int_least64_t; 57typedef _Atomic(uint_least64_t) atomic_uint_least64_t; 58typedef _Atomic(int_fast8_t) atomic_int_fast8_t; 59typedef _Atomic(uint_fast8_t) atomic_uint_fast8_t; 60typedef _Atomic(int_fast16_t) atomic_int_fast16_t; 61typedef _Atomic(uint_fast16_t) atomic_uint_fast16_t; 62typedef _Atomic(int_fast32_t) atomic_int_fast32_t; 63typedef _Atomic(uint_fast32_t) atomic_uint_fast32_t; 64typedef _Atomic(int_fast64_t) atomic_int_fast64_t; 65typedef _Atomic(uint_fast64_t) atomic_uint_fast64_t; 66typedef _Atomic(intptr_t) atomic_intptr_t; 67typedef _Atomic(uintptr_t) atomic_uintptr_t; 68typedef _Atomic(size_t) atomic_size_t; 69typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t; 70typedef _Atomic(intmax_t) atomic_intmax_t; 71typedef _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