From e01dfbc3923429a5fd9e5e7d417caa9a096a9862 Mon Sep 17 00:00:00 2001 From: fincs Date: Sat, 7 Nov 2015 01:07:11 +0100 Subject: [PATCH] synchronization.h: Add DSB & several atomic operations --- libctru/include/3ds/synchronization.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libctru/include/3ds/synchronization.h b/libctru/include/3ds/synchronization.h index c919757..c8703bc 100644 --- a/libctru/include/3ds/synchronization.h +++ b/libctru/include/3ds/synchronization.h @@ -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.