History

stdatomic: stdatomic.h header

Dmitry Selyutin committed 5 years ago

Commit f2e77421 parent 719a6b31 file · +121 −0Browse files

Showing the changes to include/stdatomic.h (1 of 1 file). Show all

Unified · Split

include/stdatomic.h+121−0
@@ -0,0 +1,121 @@
1#include <stddef.h>
2#include <stdint.h>
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8/* Memory ordering */
9typedef enum {
10 memory_order_relaxed = __ATOMIC_RELAXED,
11 memory_order_consume = __ATOMIC_CONSUME,
12 memory_order_acquire = __ATOMIC_ACQUIRE,
13 memory_order_release = __ATOMIC_RELEASE,
14 memory_order_acq_rel = __ATOMIC_ACQ_REL,
15 memory_order_seq_cst = __ATOMIC_SEQ_CST,
16} memory_order;
17
18/* Atomic typedefs */
19#ifdef __cplusplus
20typedef _Atomic(bool) atomic_bool;
21#else
22typedef _Atomic(_Bool) atomic_bool;
23#endif
24typedef _Atomic(char) atomic_char;
25typedef _Atomic(signed char) atomic_schar;
26typedef _Atomic(unsigned char) atomic_uchar;
27typedef _Atomic(short) atomic_short;
28typedef _Atomic(unsigned short) atomic_ushort;
29typedef _Atomic(int) atomic_int;
30typedef _Atomic(unsigned int) atomic_uint;
31typedef _Atomic(long) atomic_long;
32typedef _Atomic(unsigned long) atomic_ulong;
33typedef _Atomic(long long) atomic_llong;
34typedef _Atomic(unsigned long long) atomic_ullong;
35typedef _Atomic(uint_least16_t) atomic_char16_t;
36typedef _Atomic(uint_least32_t) atomic_char32_t;
37typedef _Atomic(wchar_t) atomic_wchar_t;
38typedef _Atomic(int_least8_t) atomic_int_least8_t;
39typedef _Atomic(uint_least8_t) atomic_uint_least8_t;
40typedef _Atomic(int_least16_t) atomic_int_least16_t;
41typedef _Atomic(uint_least16_t) atomic_uint_least16_t;
42typedef _Atomic(int_least32_t) atomic_int_least32_t;
43typedef _Atomic(uint_least32_t) atomic_uint_least32_t;
44typedef _Atomic(int_least64_t) atomic_int_least64_t;
45typedef _Atomic(uint_least64_t) atomic_uint_least64_t;
46typedef _Atomic(int_fast8_t) atomic_int_fast8_t;
47typedef _Atomic(uint_fast8_t) atomic_uint_fast8_t;
48typedef _Atomic(int_fast16_t) atomic_int_fast16_t;
49typedef _Atomic(uint_fast16_t) atomic_uint_fast16_t;
50typedef _Atomic(int_fast32_t) atomic_int_fast32_t;
51typedef _Atomic(uint_fast32_t) atomic_uint_fast32_t;
52typedef _Atomic(int_fast64_t) atomic_int_fast64_t;
53typedef _Atomic(uint_fast64_t) atomic_uint_fast64_t;
54typedef _Atomic(intptr_t) atomic_intptr_t;
55typedef _Atomic(uintptr_t) atomic_uintptr_t;
56typedef _Atomic(size_t) atomic_size_t;
57typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t;
58typedef _Atomic(intmax_t) atomic_intmax_t;
59typedef _Atomic(uintmax_t) atomic_uintmax_t;
60
61/* Atomic flag */
62typedef struct {
63 atomic_bool value;
64} atomic_flag;
65
66#define ATOMIC_FLAG_INIT { 0 }
67
68#define atomic_flag_test_and_set(object) \
69 __atomic_exchange(&(object)->value, 1, __ATOMIC_SEQ_CST)
70#define atomic_flag_test_and_set_explicit(object, order) \
71 __atomic_exchange(&(object)->value, 1, order)
72
73#define atomic_flag_clear(object) \
74 __atomic_store(&(object)->value, 0, __ATOMIC_SEQ_CST)
75#define atomic_flag_clear_explicit(object, order) \
76 __atomic_store(&(object)->value, 0, order)
77
78/* Generic routines */
79#define atomic_store(object, desired) \
80 __atomic_store(object, desired, __ATOMIC_SEQ_CST)
81#define atomic_store_explicit __atomic_store
82
83#define atomic_load(object) \
84 __atomic_load(object, __ATOMIC_SEQ_CST)
85#define atomic_load_explicit __atomic_load
86
87#define atomic_exchange(object, desired) \
88 __atomic_exchange(object, desired, __ATOMIC_SEQ_CST)
89#define atomic_exchange_explicit __atomic_exchange
90
91#define atomic_compare_exchange_strong(object, expected, desired) \
92 __atomic_compare_exchange_strong(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
93#define atomic_compare_exchange_strong_explicit __atomic_compare_exchange_strong
94
95#define atomic_compare_exchange_weak(object, expected, desired) \
96 __atomic_compare_exchange_weak(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
97#define atomic_compare_exchange_weak_explicit __atomic_compare_exchange_weak
98
99#define atomic_fetch_add(object, operand) \
100 __atomic_fetch_add(object, operand, __ATOMIC_SEQ_CST)
101#define atomic_fetch_add_explicit __atomic_fetch_add
102
103#define atomic_fetch_sub(object, operand) \
104 __atomic_fetch_sub(object, operand, __ATOMIC_SEQ_CST)
105#define atomic_fetch_sub_explicit __atomic_fetch_sub
106
107#define atomic_fetch_or(object, operand) \
108 __atomic_fetch_or(object, operand, __ATOMIC_SEQ_CST)
109#define atomic_fetch_or_explicit __atomic_fetch_or
110
111#define atomic_fetch_xor(object, operand) \
112 __atomic_fetch_xor(object, operand, __ATOMIC_SEQ_CST)
113#define atomic_fetch_xor_explicit __atomic_fetch_xor
114
115#define atomic_fetch_and(object, operand) \
116 __atomic_fetch_and(object, operand, __ATOMIC_SEQ_CST)
117#define atomic_fetch_and_explicit __atomic_fetch_and
118
119#ifdef __cplusplus
120} /* extern "C" */
121#endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t