| 1 | /* stdatomic.h: The ABC representation of standard C library.
|
|---|
| 2 | * C11 7.17: The header <stdatomic.h> defines several macros and declares several
|
|---|
| 3 | * types and functions for performing atomic operations on data shared
|
|---|
| 4 | * between threads.
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | #ifndef _STDATOMIC_
|
|---|
| 8 | #define _STDATOMIC_
|
|---|
| 9 |
|
|---|
| 10 | #include <stddef.h>
|
|---|
| 11 | #include <stdint.h>
|
|---|
| 12 |
|
|---|
| 13 | /* Types */
|
|---|
| 14 | typedef enum memory_order{ //defines memory ordering constraints
|
|---|
| 15 | memory_order_relaxed,
|
|---|
| 16 | memory_order_consume,
|
|---|
| 17 | memory_order_acquire,
|
|---|
| 18 | memory_order_release,
|
|---|
| 19 | memory_order_acq_rel,
|
|---|
| 20 | memory_order_seq_cst
|
|---|
| 21 | }memory_order;
|
|---|
| 22 |
|
|---|
| 23 | /* lock-free atomic boolean flag */
|
|---|
| 24 | typedef struct atomic_flag atomic_flag;
|
|---|
| 25 |
|
|---|
| 26 | typedef unsigned long int char16_t;
|
|---|
| 27 | typedef unsigned long int char32_t;
|
|---|
| 28 |
|
|---|
| 29 | /* Atomic types */
|
|---|
| 30 | typedef _Atomic _Bool atomic_bool;
|
|---|
| 31 | typedef _Atomic char atomic_char;
|
|---|
| 32 | typedef _Atomic signed char atomic_schar;
|
|---|
| 33 | typedef _Atomic unsigned char atomic_uchar;
|
|---|
| 34 | typedef _Atomic short atomic_short;
|
|---|
| 35 | typedef _Atomic unsigned short atomic_ushort;
|
|---|
| 36 | typedef _Atomic int atomic_int;
|
|---|
| 37 | typedef _Atomic unsigned int atomic_uint;
|
|---|
| 38 | typedef _Atomic long atomic_long;
|
|---|
| 39 | typedef _Atomic unsigned long atomic_ulong;
|
|---|
| 40 | typedef _Atomic long long atomic_llong;
|
|---|
| 41 | typedef _Atomic unsigned long long atomic_ullong;
|
|---|
| 42 | typedef _Atomic char16_t atomic_char16_t;
|
|---|
| 43 | typedef _Atomic char32_t atomic_char32_t;
|
|---|
| 44 | typedef _Atomic wchar_t atomic_wchar_t;
|
|---|
| 45 | typedef _Atomic int_least8_t atomic_int_least8_t;
|
|---|
| 46 | typedef _Atomic uint_least8_t atomic_uint_least8_t;
|
|---|
| 47 | typedef _Atomic int_least16_t atomic_int_least16_t;
|
|---|
| 48 | typedef _Atomic uint_least16_t atomic_uint_least16_t;
|
|---|
| 49 | typedef _Atomic int_least32_t atomic_int_least32_t;
|
|---|
| 50 | typedef _Atomic uint_least32_t atomic_uint_least32_t;
|
|---|
| 51 | typedef _Atomic int_least64_t atomic_int_least64_t;
|
|---|
| 52 | typedef _Atomic uint_least64_t atomic_uint_least64_t;
|
|---|
| 53 | typedef _Atomic int_fast8_t atomic_int_fast8_t;
|
|---|
| 54 | typedef _Atomic uint_fast8_t atomic_uint_fast8_t;
|
|---|
| 55 | typedef _Atomic int_fast16_t atomic_int_fast16_t;
|
|---|
| 56 | typedef _Atomic uint_fast16_t atomic_uint_fast16_t;
|
|---|
| 57 | typedef _Atomic int_fast32_t atomic_int_fast32_t;
|
|---|
| 58 | typedef _Atomic uint_fast32_t atomic_uint_fast32_t;
|
|---|
| 59 | typedef _Atomic int_fast64_t atomic_int_fast64_t;
|
|---|
| 60 | typedef _Atomic uint_fast64_t atomic_uint_fast64_t;
|
|---|
| 61 | typedef _Atomic intptr_t atomic_intptr_t;
|
|---|
| 62 | typedef _Atomic uintptr_t atomic_uintptr_t;
|
|---|
| 63 | typedef _Atomic size_t atomic_size_t;
|
|---|
| 64 | typedef _Atomic ptrdiff_t atomic_ptrdiff_t;
|
|---|
| 65 | typedef _Atomic intmax_t atomic_intmax_t;
|
|---|
| 66 | typedef _Atomic uintmax_t atomic_uintmax_t;
|
|---|
| 67 |
|
|---|
| 68 | typedef struct A A;
|
|---|
| 69 | typedef struct C C;
|
|---|
| 70 | typedef struct M M;
|
|---|
| 71 |
|
|---|
| 72 | /* Macros */
|
|---|
| 73 | #define ATOMIC_BOOL_LOCK_FREE _ABC_ATOMIC_BOOL_LOCK_FREE
|
|---|
| 74 | #define ATOMIC_CHAR_LOCK_FREE _ABC_ATOMIC_CHAR_LOCK_FREE
|
|---|
| 75 | #define ATOMIC_CHAR16_T_LOCK_FREE _ABC_ATOMIC_CHAR16_T_LOCK_FREE
|
|---|
| 76 | #define ATOMIC_CHAR32_T_LOCK_FREE _ABC_ATOMIC_CHAR32_T_LOCK_FREE
|
|---|
| 77 | #define ATOMIC_WCHAR_T_LOCK_FREE _ABC_ATOMIC_WCHAR_T_LOCK_FREE
|
|---|
| 78 | #define ATOMIC_SHORT_T_LOCK_FREE _ABC_ATOMIC_SHORT_T_LOCK_FREE
|
|---|
| 79 | #define ATOMIC_INT_T_LOCK_FREE _ABC_ATOMIC_INT_T_LOCK_FREE
|
|---|
| 80 | #define ATOMIC_LONG_T_LOCK_FREE _ABC_ATOMIC_LONG_T_LOCK_FREE
|
|---|
| 81 | #define ATOMIC_LLONG_T_LOCK_FREE _ABC_ATOMIC_LLONG_T_LOCK_FREE
|
|---|
| 82 | #define ATOMIC_POINTER_T_LOCK_FREE _ABC_ATOMIC_POINTER_T_LOCK_FREE
|
|---|
| 83 |
|
|---|
| 84 | #define ATOMIC_FLAG_INIT 0
|
|---|
| 85 | #define ATOMIC_VAR_INIT(value)
|
|---|
| 86 | #define kill_dependency(y)
|
|---|
| 87 |
|
|---|
| 88 | /* Functions */
|
|---|
| 89 | void atomic_thread_fence(memory_order);
|
|---|
| 90 | void atomic_signal_fence(memory_order);
|
|---|
| 91 | _Bool atomic_is_lock_free(const volatile A *);
|
|---|
| 92 | void atomic_store(volatile A *, C);
|
|---|
| 93 | void atomic_store_explicit(volatile A *, C, memory_order);
|
|---|
| 94 | C atomic_load(volatile A *);
|
|---|
| 95 | C atomic_load_explicit(volatile A *, memory_order);
|
|---|
| 96 | C atomic_exchange(volatile A *, C);
|
|---|
| 97 | C atomic_exchange_explicit(volatile A *, C, memory_order);
|
|---|
| 98 | _Bool atomic_compare_exchange_strong(volatile A *, C *, C );
|
|---|
| 99 | _Bool atomic_compare_exchange_strong_explicit(volatile A *, C *, C, memory_order, memory_order);
|
|---|
| 100 | _Bool atomic_compare_exchange_weak(volatile A *, C *, C );
|
|---|
| 101 | _Bool atomic_compare_exchange_weak_explicit(volatile A *, C *, C, memory_order, memory_order);
|
|---|
| 102 | C atomic_fetch_key(volatile A *, M);
|
|---|
| 103 | C atomic_fetch_key_explicit(volatile A *, M, memory_order);
|
|---|
| 104 | _Bool atomic_flag_test_and_set(volatile atomic_flag *);
|
|---|
| 105 | _Bool atomic_flag_test_and_set_explicit(volatile atomic_flag *, memory_order);
|
|---|
| 106 | void atomic_flag_clear(volatile atomic_flag *);
|
|---|
| 107 | void atomic_flag_clear_explicit(volatile atomic_flag *, memory_order);
|
|---|
| 108 |
|
|---|
| 109 | #endif
|
|---|