@@ -103,6 +103,15 @@ static inline void utils_atomic_load_acquire_u64(uint64_t *ptr, uint64_t *out) {
103
103
*out = *(uint64_t *)&ret;
104
104
}
105
105
106
+ // There is no good way to do atomic_load on windows...
107
+ static inline void utils_atomic_load_acquire_u8 (uint8_t *ptr, uint8_t *out) {
108
+ // On Windows, there is no equivalent to __atomic_load, so we use cmpxchg
109
+ // with 0, 0 here. This will always return the value under the pointer
110
+ // without writing anything.
111
+ char ret = _InterlockedCompareExchange8 ((char volatile *)ptr, 0 , 0 );
112
+ *out = *(uint8_t *)&ret;
113
+ }
114
+
106
115
static inline void utils_atomic_load_acquire_ptr (void **ptr, void **out) {
107
116
ASSERT_IS_ALIGNED ((uintptr_t )ptr, 8 );
108
117
uintptr_t ret = (uintptr_t )InterlockedCompareExchangePointer (ptr, 0 , 0 );
@@ -114,6 +123,10 @@ static inline void utils_atomic_store_release_u64(uint64_t *ptr, uint64_t val) {
114
123
InterlockedExchange64 ((LONG64 volatile *)ptr, val);
115
124
}
116
125
126
+ static inline void utils_atomic_store_release_u8 (uint8_t *ptr, uint8_t val) {
127
+ InterlockedExchange8 ((CHAR volatile *)ptr, val);
128
+ }
129
+
117
130
static inline void utils_atomic_store_release_ptr (void **ptr, void *val) {
118
131
ASSERT_IS_ALIGNED ((uintptr_t )ptr, 8 );
119
132
InterlockedExchangePointer (ptr, val);
@@ -167,6 +180,11 @@ static inline void utils_atomic_load_acquire_u64(uint64_t *ptr, uint64_t *out) {
167
180
utils_annotate_acquire (ptr);
168
181
}
169
182
183
+ static inline void utils_atomic_load_acquire_u8 (uint8_t *ptr, uint8_t *out) {
184
+ __atomic_load (ptr, out, memory_order_acquire);
185
+ utils_annotate_acquire (ptr);
186
+ }
187
+
170
188
static inline void utils_atomic_load_acquire_ptr (void **ptr, void **out) {
171
189
ASSERT_IS_ALIGNED ((uintptr_t )ptr, 8 );
172
190
ASSERT_IS_ALIGNED ((uintptr_t )out, 8 );
@@ -180,6 +198,11 @@ static inline void utils_atomic_store_release_u64(uint64_t *ptr, uint64_t val) {
180
198
__atomic_store_n (ptr, val, memory_order_release);
181
199
}
182
200
201
+ static inline void utils_atomic_store_release_u8 (uint8_t *ptr, uint8_t val) {
202
+ utils_annotate_release (ptr);
203
+ __atomic_store_n (ptr, val, memory_order_release);
204
+ }
205
+
183
206
static inline void utils_atomic_store_release_ptr (void **ptr, void *val) {
184
207
ASSERT_IS_ALIGNED ((uintptr_t )ptr, 8 );
185
208
utils_annotate_release (ptr);
0 commit comments