Skip to content

Commit 965fc67

Browse files
committed
Add utils_atomic_store_release_u64() to utils
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 8cc1d42 commit 965fc67

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/utils/utils_concurrency.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ static inline bool utils_compare_exchange_u64(uint64_t *ptr, uint64_t *expected,
152152
return false;
153153
}
154154

155+
static inline void utils_atomic_store_release_u64(void *ptr, uint64_t val) {
156+
ASSERT_IS_ALIGNED((uintptr_t)ptr, 8);
157+
LONG64 out;
158+
LONG64 desired = (LONG64)val;
159+
LONG64 expected = 0;
160+
while (expected != (out = InterlockedCompareExchange64(
161+
(LONG64 volatile *)ptr, desired, expected))) {
162+
expected = out;
163+
}
164+
}
165+
155166
#else // !defined(_WIN32)
156167

157168
static inline void utils_atomic_load_acquire_u64(uint64_t *ptr, uint64_t *out) {
@@ -168,6 +179,11 @@ static inline void utils_atomic_load_acquire_ptr(void **ptr, void **out) {
168179
utils_annotate_acquire(ptr);
169180
}
170181

182+
static inline void utils_atomic_store_release_u64(void *ptr, uint64_t val) {
183+
ASSERT_IS_ALIGNED((uintptr_t)ptr, 8);
184+
__atomic_store_n((uintptr_t *)ptr, (uintptr_t)val, memory_order_release);
185+
}
186+
171187
static inline void utils_atomic_store_release_ptr(void **ptr, void *val) {
172188
ASSERT_IS_ALIGNED((uintptr_t)ptr, 8);
173189
utils_annotate_release(ptr);

0 commit comments

Comments
 (0)