Skip to content

Commit f5cf732

Browse files
committed
zig.h: add missing msvc atomics
1 parent 3f1c51c commit f5cf732

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

lib/zig.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3643,18 +3643,29 @@ zig_msvc_atomics(u64, uint64_t, __int64, 64)
36433643
zig_msvc_atomics(i64, int64_t, __int64, 64)
36443644
#endif
36453645

3646-
#define zig_msvc_flt_atomics(Type, ReprType, suffix) \
3646+
#define zig_msvc_flt_atomics(Type, SigType, suffix) \
36473647
static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \
3648-
ReprType exchange; \
3649-
ReprType comparand; \
3650-
ReprType initial; \
3648+
SigType exchange; \
3649+
SigType comparand; \
3650+
SigType initial; \
36513651
bool success; \
36523652
memcpy(&comparand, expected, sizeof(comparand)); \
36533653
memcpy(&exchange, &desired, sizeof(exchange)); \
3654-
initial = _InterlockedCompareExchange##suffix((ReprType volatile*)obj, exchange, comparand); \
3654+
initial = _InterlockedCompareExchange##suffix((SigType volatile*)obj, exchange, comparand); \
36553655
success = initial == comparand; \
36563656
if (!success) memcpy(expected, &initial, sizeof(*expected)); \
36573657
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; \
36583669
}
36593670
zig_msvc_flt_atomics(f32, long, )
36603671
#if _M_X64

0 commit comments

Comments
 (0)