From 2c3597646d15ba5bc8b18cec51a34a3205a171c7 Mon Sep 17 00:00:00 2001 From: jacob Date: Thu, 28 Mar 2024 15:31:15 -0500 Subject: [PATCH] atomic ptr --- src/atomic.h | 3 +++ src/common.h | 4 ++++ src/log.c | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/atomic.h b/src/atomic.h index 51b17454..400296c7 100644 --- a/src/atomic.h +++ b/src/atomic.h @@ -31,6 +31,9 @@ FORCE_INLINE u64 atomic_u64_eval_add(struct atomic_u64 *x, u64 a) { return _Inte FORCE_INLINE u64 atomic_u64_eval_exchange(struct atomic_u64 *x, u64 e) { return _InterlockedExchange64((volatile i64 *)&x->_v, e); } FORCE_INLINE u64 atomic_u64_eval_compare_exchange(struct atomic_u64 *x, u64 c, u64 e) { return _InterlockedCompareExchange64((volatile i64 *)&x->_v, e, c); } +FORCE_INLINE void *atomic_ptr_eval(struct atomic_ptr *x) { return (void *)_InterlockedExchangeAdd64((volatile i64 *)&x->_v, 0); } +FORCE_INLINE void *atomic_ptr_eval_compare_exchange(struct atomic_ptr *x, void *c, void *e) { return (void *)_InterlockedCompareExchange64((volatile i64 *)&x->_v, (i64)e, (i64)c); } + #else # error "Atomics not implemented" #endif diff --git a/src/common.h b/src/common.h index cc671705..2953a42b 100644 --- a/src/common.h +++ b/src/common.h @@ -308,6 +308,10 @@ struct atomic_u64 { volatile u64 _v; }; +struct atomic_ptr { + volatile void *_v; +}; + /* ========================== * * Common structs * ========================== */ diff --git a/src/log.c b/src/log.c index 26460a06..1a50ef4a 100644 --- a/src/log.c +++ b/src/log.c @@ -125,7 +125,7 @@ void _log(i32 level, struct string msg) ASSERT_INITIALIZED; if (level < 0 || level >= LOG_LEVEL_COUNT) { - sys_panic(STR("Invalid log level")); + sys_panic_raw("Invalid log level"); } struct temp_arena scratch = scratch_begin_no_conflict();