From dbdd95d079ed1bfaba8e3151870ad9aae202b653 Mon Sep 17 00:00:00 2001 From: "Chloe M." Date: Thu, 25 Jun 2026 19:10:08 +0000 Subject: [PATCH] sdk: Add atomic operations groundwork Signed-off-by: Chloe M. --- sdk/head/atomic.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 sdk/head/atomic.h diff --git a/sdk/head/atomic.h b/sdk/head/atomic.h new file mode 100644 index 0000000..7efa765 --- /dev/null +++ b/sdk/head/atomic.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Atomic operations + * Author: Chloe M. + */ + +#ifndef _SDK_ATOMIC_H_ +#define _SDK_ATOMIC_H_ 1 + +#include + +static inline ULONG +AtomicAddLongNv(volatile ULONG *Ptr, ULONG Value) +{ + return __sync_add_and_fetch(Ptr, Value); +} + +static inline UQUAD +AtomicAddQuadNv(volatile UQUAD *Ptr, UQUAD Value) +{ + return __sync_add_and_fetch(Ptr, Value); +} + +static inline ULONG +AtomicSubLongNv(volatile ULONG *Ptr, ULONG Value) +{ + return __sync_sub_and_fetch(Ptr, Value); +} + +static inline ULONG +AtomicSubQuadNv(volatile UQUAD *Ptr, UQUAD Value) +{ + return __sync_sub_and_fetch(Ptr, Value); +} + +/* Atomic increment and fetch operations */ +#define AtomicIncLong(P) AtomicAddLongNv((P), 1) +#define AtomicIncQuad(P) AtomicAddQuadNv((P), 1) + +/* Atomic decrement and fetch operations */ +#define AtomicDecLong(P) AtomicSubLongNv((P), 1) +#define AtomicDecQuad(P) AtomicSubQuadNv((P), 1) + +#endif /* !_SDK_ATOMIC_H_ */