sdk: Add atomic operations groundwork
Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
@@ -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 <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_ */
|
||||
Reference in New Issue
Block a user