@@ -103,6 +103,15 @@ static inline void utils_atomic_load_acquire_u64(uint64_t *ptr, uint64_t *out) {
103103 *out = *(uint64_t *)&ret;
104104}
105105
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+
106115static inline void utils_atomic_load_acquire_ptr (void **ptr, void **out) {
107116 ASSERT_IS_ALIGNED ((uintptr_t )ptr, 8 );
108117 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) {
114123 InterlockedExchange64 ((LONG64 volatile *)ptr, val);
115124}
116125
126+ static inline void utils_atomic_store_release_u8 (uint8_t *ptr, uint8_t val) {
127+ InterlockedExchange8 ((CHAR volatile *)ptr, val);
128+ }
129+
117130static inline void utils_atomic_store_release_ptr (void **ptr, void *val) {
118131 ASSERT_IS_ALIGNED ((uintptr_t )ptr, 8 );
119132 InterlockedExchangePointer (ptr, val);
@@ -167,6 +180,11 @@ static inline void utils_atomic_load_acquire_u64(uint64_t *ptr, uint64_t *out) {
167180 utils_annotate_acquire (ptr);
168181}
169182
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+
170188static inline void utils_atomic_load_acquire_ptr (void **ptr, void **out) {
171189 ASSERT_IS_ALIGNED ((uintptr_t )ptr, 8 );
172190 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) {
180198 __atomic_store_n (ptr, val, memory_order_release);
181199}
182200
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+
183206static inline void utils_atomic_store_release_ptr (void **ptr, void *val) {
184207 ASSERT_IS_ALIGNED ((uintptr_t )ptr, 8 );
185208 utils_annotate_release (ptr);
0 commit comments