Ylva And Malin
ym_atomic.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdatomic.h>
4 #include <stdint.h>
5 #include <assert.h>
6 #include <limits.h>
7 #include <ym_assert.h>
8 
10 // Core assertions for ym_atomics.
12 // Atomics should be its own project, does not belong in here.
13 #ifndef WIN32
14 static_assert(CHAR_BIT == 8, "char is not 8 bit on this platform");
15 static_assert(sizeof(atomic_schar) * CHAR_BIT == 8, "atomic_schar is not 8 bit");
16 static_assert(sizeof(atomic_short) * CHAR_BIT == 16, "atomic_short is not 16 bit");
17 static_assert(sizeof(atomic_int) * CHAR_BIT == 32, "atomic_int is not 32 bit");
18 static_assert(sizeof(atomic_long) * CHAR_BIT == 64, "atomic_long is not 64 bit");
19 
20 static_assert(sizeof(atomic_uchar) * CHAR_BIT == 8, "atomic_uchar is not 8 bit");
21 static_assert(sizeof(atomic_ushort) * CHAR_BIT == 16, "atomic_ushort is not 16 bit");
22 static_assert(sizeof(atomic_uint) * CHAR_BIT == 32, "atomic_int is not 32 bit");
23 static_assert(sizeof(atomic_ulong) * CHAR_BIT == 64, "atomic_long is not 64 bit");
24 
25 static_assert(ATOMIC_BOOL_LOCK_FREE == 2, "ATOMIC_BOOL is not lock free");
26 static_assert(ATOMIC_CHAR_LOCK_FREE == 2, "ATOMIC_CHAR is not lock free");
27 static_assert(ATOMIC_CHAR16_T_LOCK_FREE == 2, "ATOMIC_CHAR16_T is not lock free");
28 static_assert(ATOMIC_CHAR32_T_LOCK_FREE == 2, "ATOMIC_CHAR32_T is not lock free");
29 static_assert(ATOMIC_WCHAR_T_LOCK_FREE == 2, "ATOMIC_WCHAR_T is not lock free");
30 static_assert(ATOMIC_SHORT_LOCK_FREE == 2, "ATOMIC_SHORT is not lock free");
31 static_assert(ATOMIC_INT_LOCK_FREE == 2, "ATOMIC_INT is not lock free");
32 static_assert(ATOMIC_LONG_LOCK_FREE == 2, "ATOMIC_LONG is not lock free");
33 static_assert(ATOMIC_LLONG_LOCK_FREE == 2, "ATOMIC_LLONG is not lock free");
34 static_assert(ATOMIC_POINTER_LOCK_FREE == 2, "ATOMIC_POINTER is not lock free");
35 #endif
36 typedef atomic_schar atomic_int8_t;
66 typedef atomic_short atomic_int16_t;
67 typedef atomic_int atomic_int32_t;
68 typedef atomic_long atomic_int64_t;
69 
99 typedef atomic_uchar atomic_uint8_t;
100 typedef atomic_ushort atomic_uint16_t;
101 typedef atomic_uint atomic_uint32_t;
102 typedef atomic_ulong atomic_uint64_t;
atomic_ulong atomic_uint64_t
Atomic unsigned 64-bit integer. Supplied because C11 does not mandate fixed width atomic support...
Definition: ym_atomic.h:102
atomic_uint atomic_uint32_t
Atomic unsigned 32-bit integer. Supplied because C11 does not mandate fixed width atomic support...
Definition: ym_atomic.h:101
atomic_long atomic_int64_t
Atomic signed 64-bit integer. Supplied because C11 does not mandate fixed width atomic support...
Definition: ym_atomic.h:68
atomic_int atomic_int32_t
Atomic signed 32-bit integer. Supplied because C11 does not mandate fixed width atomic support...
Definition: ym_atomic.h:67
atomic_ushort atomic_uint16_t
Atomic unsigned 16-bit integer. Supplied because C11 does not mandate fixed width atomic support...
Definition: ym_atomic.h:100
atomic_schar atomic_int8_t
Atomic signed 8-bit integer. Supplied because C11 does not mandate fixed width atomic support...
Definition: ym_atomic.h:65
atomic_uchar atomic_uint8_t
Atomic unsigned 8-bit integer. Supplied because C11 does not mandate fixed width atomic support...
Definition: ym_atomic.h:99
atomic_short atomic_int16_t
Atomic signed 16-bit integer. Supplied because C11 does not mandate fixed width atomic support...
Definition: ym_atomic.h:66