Fix null pointer constants
[tinycc.git] / include / stdatomic.h
blobf00c62f09ee4c2495afc54e502d86e2a6a747886
1 /* This file is derived from clang's stdatomic.h */
3 /*===---- stdatomic.h - Standard header for atomic types and operations -----===
5 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 * See https://llvm.org/LICENSE.txt for license information.
7 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 *===-----------------------------------------------------------------------===
12 #ifndef _STDATOMIC_H
13 #define _STDATOMIC_H
15 #include <stddef.h>
16 #include <stdint.h>
18 #define __ATOMIC_RELAXED 0
19 #define __ATOMIC_CONSUME 1
20 #define __ATOMIC_ACQUIRE 2
21 #define __ATOMIC_RELEASE 3
22 #define __ATOMIC_ACQ_REL 4
23 #define __ATOMIC_SEQ_CST 5
25 /* Memory ordering */
26 typedef enum {
27 memory_order_relaxed = __ATOMIC_RELAXED,
28 memory_order_consume = __ATOMIC_CONSUME,
29 memory_order_acquire = __ATOMIC_ACQUIRE,
30 memory_order_release = __ATOMIC_RELEASE,
31 memory_order_acq_rel = __ATOMIC_ACQ_REL,
32 memory_order_seq_cst = __ATOMIC_SEQ_CST,
33 } memory_order;
35 /* Atomic typedefs */
36 typedef _Atomic(_Bool) atomic_bool;
37 typedef _Atomic(char) atomic_char;
38 typedef _Atomic(signed char) atomic_schar;
39 typedef _Atomic(unsigned char) atomic_uchar;
40 typedef _Atomic(short) atomic_short;
41 typedef _Atomic(unsigned short) atomic_ushort;
42 typedef _Atomic(int) atomic_int;
43 typedef _Atomic(unsigned int) atomic_uint;
44 typedef _Atomic(long) atomic_long;
45 typedef _Atomic(unsigned long) atomic_ulong;
46 typedef _Atomic(long long) atomic_llong;
47 typedef _Atomic(unsigned long long) atomic_ullong;
48 typedef _Atomic(uint_least16_t) atomic_char16_t;
49 typedef _Atomic(uint_least32_t) atomic_char32_t;
50 typedef _Atomic(wchar_t) atomic_wchar_t;
51 typedef _Atomic(int_least8_t) atomic_int_least8_t;
52 typedef _Atomic(uint_least8_t) atomic_uint_least8_t;
53 typedef _Atomic(int_least16_t) atomic_int_least16_t;
54 typedef _Atomic(uint_least16_t) atomic_uint_least16_t;
55 typedef _Atomic(int_least32_t) atomic_int_least32_t;
56 typedef _Atomic(uint_least32_t) atomic_uint_least32_t;
57 typedef _Atomic(int_least64_t) atomic_int_least64_t;
58 typedef _Atomic(uint_least64_t) atomic_uint_least64_t;
59 typedef _Atomic(int_fast8_t) atomic_int_fast8_t;
60 typedef _Atomic(uint_fast8_t) atomic_uint_fast8_t;
61 typedef _Atomic(int_fast16_t) atomic_int_fast16_t;
62 typedef _Atomic(uint_fast16_t) atomic_uint_fast16_t;
63 typedef _Atomic(int_fast32_t) atomic_int_fast32_t;
64 typedef _Atomic(uint_fast32_t) atomic_uint_fast32_t;
65 typedef _Atomic(int_fast64_t) atomic_int_fast64_t;
66 typedef _Atomic(uint_fast64_t) atomic_uint_fast64_t;
67 typedef _Atomic(intptr_t) atomic_intptr_t;
68 typedef _Atomic(uintptr_t) atomic_uintptr_t;
69 typedef _Atomic(size_t) atomic_size_t;
70 typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t;
71 typedef _Atomic(intmax_t) atomic_intmax_t;
72 typedef _Atomic(uintmax_t) atomic_uintmax_t;
74 /* Atomic flag */
75 typedef struct {
76 atomic_bool value;
77 } atomic_flag;
79 #define ATOMIC_FLAG_INIT {0}
81 #define atomic_flag_test_and_set(object) \
82 __atomic_exchange(&(object)->value, 1, __ATOMIC_SEQ_CST)
83 #define atomic_flag_test_and_set_explicit(object, order) \
84 __atomic_exchange(&(object)->value, 1, order)
86 #define atomic_flag_clear(object) \
87 __atomic_store(&(object)->value, 0, __ATOMIC_SEQ_CST)
88 #define atomic_flag_clear_explicit(object, order) \
89 __atomic_store(&(object)->value, 0, order)
91 /* Generic routines */
92 #define atomic_init(object, desired) \
93 __atomic_store(object, desired, __ATOMIC_RELAXED)
95 #define atomic_store(object, desired) \
96 __atomic_store(object, desired, __ATOMIC_SEQ_CST)
97 #define atomic_store_explicit __atomic_store
99 #define atomic_load(object) \
100 __atomic_load(object, __ATOMIC_SEQ_CST)
101 #define atomic_load_explicit __atomic_load
103 #define atomic_exchange(object, desired) \
104 __atomic_exchange(object, desired, __ATOMIC_SEQ_CST)
105 #define atomic_exchange_explicit __atomic_exchange
107 #define atomic_compare_exchange_strong(object, expected, desired) \
108 __atomic_compare_exchange(object, expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
109 #define atomic_compare_exchange_strong_explicit(object, expected, desired, success, failure) \
110 __atomic_compare_exchange(object, expected, desired, 0, success, failure)
112 #define atomic_compare_exchange_weak(object, expected, desired) \
113 __atomic_compare_exchange(object, expected, desired, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
114 #define atomic_compare_exchange_weak_explicit(object, expected, desired, success, failure) \
115 __atomic_compare_exchange(object, expected, desired, 1, success, failure)
117 #define atomic_fetch_add(object, operand) \
118 __atomic_fetch_add(object, operand, __ATOMIC_SEQ_CST)
119 #define atomic_fetch_add_explicit __atomic_fetch_add
121 #define atomic_fetch_sub(object, operand) \
122 __atomic_fetch_sub(object, operand, __ATOMIC_SEQ_CST)
123 #define atomic_fetch_sub_explicit __atomic_fetch_sub
125 #define atomic_fetch_or(object, operand) \
126 __atomic_fetch_or(object, operand, __ATOMIC_SEQ_CST)
127 #define atomic_fetch_or_explicit __atomic_fetch_or
129 #define atomic_fetch_xor(object, operand) \
130 __atomic_fetch_xor(object, operand, __ATOMIC_SEQ_CST)
131 #define atomic_fetch_xor_explicit __atomic_fetch_xor
133 #define atomic_fetch_and(object, operand) \
134 __atomic_fetch_and(object, operand, __ATOMIC_SEQ_CST)
135 #define atomic_fetch_and_explicit __atomic_fetch_and
137 #endif /* _STDATOMIC_H */