authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-04-21 23:26:29-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-04-22 01:16:25-04:00
logf5cf732659d1bf3112c828ef9798db445ff53f3c
treeaf5fea4c6026f1a4f51b2a56fabdbb49d778d9d5
parent3f1c51ca906719fe2a064a73295ada230e34f1c2

zig.h: add missing msvc atomics


1 files changed, 16 insertions(+), 5 deletions(-)

lib/zig.h+16-5
...@@ -3643,18 +3643,29 @@ zig_msvc_atomics(u64, uint64_t, __int64, 64)...@@ -3643,18 +3643,29 @@ zig_msvc_atomics(u64, uint64_t, __int64, 64)
3643zig_msvc_atomics(i64, int64_t, __int64, 64)3643zig_msvc_atomics(i64, int64_t, __int64, 64)
3644#endif3644#endif
36453645
3646#define zig_msvc_flt_atomics(Type, ReprType, suffix) \3646#define zig_msvc_flt_atomics(Type, SigType, suffix) \
3647 static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \3647 static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \
3648 ReprType exchange; \3648 SigType exchange; \
3649 ReprType comparand; \3649 SigType comparand; \
3650 ReprType initial; \3650 SigType initial; \
3651 bool success; \3651 bool success; \
3652 memcpy(&comparand, expected, sizeof(comparand)); \3652 memcpy(&comparand, expected, sizeof(comparand)); \
3653 memcpy(&exchange, &desired, sizeof(exchange)); \3653 memcpy(&exchange, &desired, sizeof(exchange)); \
3654 initial = _InterlockedCompareExchange##suffix((ReprType volatile*)obj, exchange, comparand); \3654 initial = _InterlockedCompareExchange##suffix((SigType volatile*)obj, exchange, comparand); \
3655 success = initial == comparand; \3655 success = initial == comparand; \
3656 if (!success) memcpy(expected, &initial, sizeof(*expected)); \3656 if (!success) memcpy(expected, &initial, sizeof(*expected)); \
3657 return success; \3657 return success; \
3658 } \
3659 static inline void zig_msvc_atomic_store_##Type(zig_##Type volatile* obj, zig_##Type arg) { \
3660 SigType value; \
3661 memcpy(&value, &arg, sizeof(value)); \
3662 (void)_InterlockedExchange##suffix((SigType volatile*)obj, value); \
3663 } \
3664 static inline zig_##Type zig_msvc_atomic_load_##Type(zig_##Type volatile* obj) { \
3665 zig_##Type result; \
3666 SigType initial = _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)0); \
3667 memcpy(&result, &initial, sizeof(result)); \
3668 return result; \
3658 }3669 }
3659zig_msvc_flt_atomics(f32, long, )3670zig_msvc_flt_atomics(f32, long, )
3660#if _M_X643671#if _M_X64