Files
Chloe M. dbdd95d079 sdk: Add atomic operations groundwork
Signed-off-by: Chloe M. <chloe@mensia.org>
2026-06-25 19:10:08 +00:00

47 lines
1003 B
C

/*
* 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 <stdef.h>
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_ */