synchronization.h: Add DSB & several atomic operations
This commit is contained in:
parent
7b25a0d4d4
commit
e01dfbc392
@ -15,6 +15,12 @@ typedef struct
|
||||
u32 counter; ///< Lock count.
|
||||
} RecursiveLock;
|
||||
|
||||
/// Performs a Data Synchronization Barrier operation.
|
||||
static inline void __dsb(void)
|
||||
{
|
||||
__asm__ __volatile__("mcr p15, 0, %[val], c7, c10, 4" :: [val] "r" (0) : "memory");
|
||||
}
|
||||
|
||||
/// Performs a clrex operation.
|
||||
static inline void __clrex(void)
|
||||
{
|
||||
@ -46,6 +52,17 @@ static inline bool __strex(s32* addr, s32 val)
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Performs an atomic pre-increment operation.
|
||||
#define AtomicIncrement(ptr) __atomic_add_fetch((u32*)(ptr), 1, __ATOMIC_SEQ_CST)
|
||||
/// Performs an atomic pre-decrement operation.
|
||||
#define AtomicDecrement(ptr) __atomic_sub_fetch((u32*)(ptr), 1, __ATOMIC_SEQ_CST)
|
||||
/// Performs an atomic post-increment operation.
|
||||
#define AtomicPostIncrement(ptr) __atomic_fetch_add((u32*)(ptr), 1, __ATOMIC_SEQ_CST)
|
||||
/// Performs an atomic post-decrement operation.
|
||||
#define AtomicPostDecrement(ptr) __atomic_fetch_sub((u32*)(ptr), 1, __ATOMIC_SEQ_CST)
|
||||
/// Performs an atomic swap operation.
|
||||
#define AtomicSwap(ptr, value) __atomic_exchange_n((u32*)(ptr), (value), __ATOMIC_SEQ_CST)
|
||||
|
||||
/**
|
||||
* @brief Initializes a light lock.
|
||||
* @param lock Pointer to the lock.
|
||||
|
Loading…
Reference in New Issue
Block a user