From 84a1e7455c158441dd7b33d2eb296cc33dd5a6df Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 25 Aug 2018 11:41:44 -0700 Subject: fixes #674 want 64-bit atomics (for stats) --- src/platform/windows/win_thread.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/platform/windows/win_thread.c') diff --git a/src/platform/windows/win_thread.c b/src/platform/windows/win_thread.c index b9743c5e..f80c8e3f 100644 --- a/src/platform/windows/win_thread.c +++ b/src/platform/windows/win_thread.c @@ -121,6 +121,44 @@ nni_atomic_flag_reset(nni_atomic_flag *f) InterlockedExchange(&f->f, 0); } +void +nni_atomic_inc64(nni_atomic_u64 *v, uint64_t bump) +{ + InterlockedAddNoFence64(&v->v, (LONGLONG) bump); +} + +void +nni_atomic_dec64(nni_atomic_u64 *v, uint64_t bump) +{ + // Windows lacks a sub, so we add the negative. + InterlockedAddNoFence64(&v->v, (0ll - (LONGLONG) bump)); +} + +uint64_t +nni_atomic_get64(nni_atomic_u64 *v) +{ + + return ((uint64_t)(InterlockedExchangeAdd64(&v->v, 0))); +} + +void +nni_atomic_set64(nni_atomic_u64 *v, uint64_t u) +{ + return (InterlockedExchange64(&v->v, (LONGLONG) u)); +} + +uint64_t +nni_atomic_swap64(nni_atomic_u64 *v, uint64_t u) +{ + return ((uint64_t)(InterlockedExchange64(&v->v, (LONGLONG) u))); +} + +void +nni_atomic_init64(nni_atomic_u64 *v) +{ + InterlockedExchange64(&v->v, 0); +} + static unsigned int __stdcall nni_plat_thr_main(void *arg) { nni_plat_thr *thr = arg; -- cgit v1.2.3-70-g09d2