36 __asm__ __volatile__(
"mcr p15, 0, %[val], c7, c10, 4" :: [val]
"r" (0) :
"memory");
42 __asm__ __volatile__(
"mcr p15, 0, %[val], c7, c10, 5" :: [val]
"r" (0) :
"memory");
48 __asm__ __volatile__(
"mcr p15, 0, %[val], c7, c5, 4" :: [val]
"r" (0) :
"memory");
54 __asm__ __volatile__(
"clrex" :::
"memory");
65 __asm__ __volatile__(
"ldrex %[val], %[addr]" : [val]
"=r" (val) : [addr]
"Q" (*addr));
78 __asm__ __volatile__(
"strex %[res], %[val], %[addr]" : [res]
"=&r" (res) : [val]
"r" (val), [addr]
"Q" (*addr));
90 __asm__ __volatile__(
"ldrexh %[val], %[addr]" : [val]
"=r" (val) : [addr]
"Q" (*addr));
103 __asm__ __volatile__(
"strexh %[res], %[val], %[addr]" : [res]
"=&r" (res) : [val]
"r" (val), [addr]
"Q" (*addr));
115 __asm__ __volatile__(
"ldrexb %[val], %[addr]" : [val]
"=r" (val) : [addr]
"Q" (*addr));
128 __asm__ __volatile__(
"strexb %[res], %[val], %[addr]" : [res]
"=&r" (res) : [val]
"r" (val), [addr]
"Q" (*addr));
133 #define AtomicIncrement(ptr) __atomic_add_fetch((u32*)(ptr), 1, __ATOMIC_SEQ_CST)
135 #define AtomicDecrement(ptr) __atomic_sub_fetch((u32*)(ptr), 1, __ATOMIC_SEQ_CST)
137 #define AtomicPostIncrement(ptr) __atomic_fetch_add((u32*)(ptr), 1, __ATOMIC_SEQ_CST)
139 #define AtomicPostDecrement(ptr) __atomic_fetch_sub((u32*)(ptr), 1, __ATOMIC_SEQ_CST)
141 #define AtomicSwap(ptr, value) __atomic_exchange_n((u32*)(ptr), (value), __ATOMIC_SEQ_CST)
A light event.
Definition: synchronization.h:20
LightLock lock
Lock used for sticky timer operation.
Definition: synchronization.h:22
s32 state
State of the event: -2=cleared sticky, -1=cleared oneshot, 0=signaled oneshot, 1=signaled sticky.
Definition: synchronization.h:21
A light semaphore.
Definition: synchronization.h:27
s32 current_count
The current release count of the semaphore.
Definition: synchronization.h:28
s16 num_threads_acq
Number of threads concurrently acquiring the semaphore.
Definition: synchronization.h:29
s16 max_count
The maximum release count of the semaphore.
Definition: synchronization.h:30
ArbitrationType
Arbitration modes.
Definition: svc.h:88
#define ARBITRATION_SIGNAL_ALL
Special value to signal all the threads.
Definition: svc.h:97
ResetType
Reset types (for use with events and timers)
Definition: svc.h:105
void LightEvent_Wait(LightEvent *event)
Waits on a light event.
_LOCK_T LightLock
A light lock.
Definition: synchronization.h:10
Result syncArbitrateAddress(s32 *addr, ArbitrationType type, s32 value)
Function used to implement user-mode synchronization primitives.
int LightLock_TryLock(LightLock *lock)
Attempts to lock a light lock.
void RecursiveLock_Init(RecursiveLock *lock)
Initializes a recursive lock.
static bool __strexh(u16 *addr, u16 val)
Performs a strexh operation.
Definition: synchronization.h:100
void LightEvent_Init(LightEvent *event, ResetType reset_type)
Initializes a light event.
int LightEvent_TryWait(LightEvent *event)
Attempts to wait on a light event.
void LightEvent_Pulse(LightEvent *event)
Wakes up threads waiting on a sticky light event without signaling it.
Result syncArbitrateAddressWithTimeout(s32 *addr, ArbitrationType type, s32 value, s64 timeout_ns)
Function used to implement user-mode synchronization primitives (with timeout).
static void CondVar_Signal(CondVar *cv)
Wakes up a single thread waiting on a condition variable.
Definition: synchronization.h:262
static u8 __ldrexb(u8 *addr)
Performs a ldrexb operation.
Definition: synchronization.h:112
void LightSemaphore_Release(LightSemaphore *semaphore, s32 count)
Releases a light semaphore.
void CondVar_WakeUp(CondVar *cv, s32 num_threads)
Wakes up threads waiting on a condition variable.
int LightSemaphore_TryAcquire(LightSemaphore *semaphore, s32 count)
Attempts to acquire a light semaphore.
static void __dsb(void)
Performs a Data Synchronization Barrier operation.
Definition: synchronization.h:34
void RecursiveLock_Unlock(RecursiveLock *lock)
Unlocks a recursive lock.
void LightEvent_Clear(LightEvent *event)
Clears a light event.
s32 CondVar
A condition variable.
Definition: synchronization.h:16
void LightLock_Init(LightLock *lock)
Initializes a light lock.
void LightLock_Unlock(LightLock *lock)
Unlocks a light lock.
int RecursiveLock_TryLock(RecursiveLock *lock)
Attempts to lock a recursive lock.
static void __isb(void)
Performs an Instruction Synchronization Barrier (officially "flush prefetch buffer") operation.
Definition: synchronization.h:46
void CondVar_Wait(CondVar *cv, LightLock *lock)
Waits on a condition variable.
static s32 __ldrex(s32 *addr)
Performs a ldrex operation.
Definition: synchronization.h:62
int CondVar_WaitTimeout(CondVar *cv, LightLock *lock, s64 timeout_ns)
Waits on a condition variable with a timeout.
int LightEvent_WaitTimeout(LightEvent *event, s64 timeout_ns)
Waits on a light event until either the event is signaled or the timeout is reached.
static void __dmb(void)
Performs a Data Memory Barrier operation.
Definition: synchronization.h:40
void CondVar_Init(CondVar *cv)
Initializes a condition variable.
static void CondVar_Broadcast(CondVar *cv)
Wakes up all threads waiting on a condition variable.
Definition: synchronization.h:271
static u16 __ldrexh(u16 *addr)
Performs a ldrexh operation.
Definition: synchronization.h:87
void LightEvent_Signal(LightEvent *event)
Signals a light event, waking up threads waiting on it.
static bool __strexb(u8 *addr, u8 val)
Performs a strexb operation.
Definition: synchronization.h:125
void LightSemaphore_Init(LightSemaphore *semaphore, s16 initial_count, s16 max_count)
Initializes a light semaphore.
void LightSemaphore_Acquire(LightSemaphore *semaphore, s32 count)
Acquires a light semaphore.
_LOCK_RECURSIVE_T RecursiveLock
A recursive lock.
Definition: synchronization.h:13
static bool __strex(s32 *addr, s32 val)
Performs a strex operation.
Definition: synchronization.h:75
void LightLock_Lock(LightLock *lock)
Locks a light lock.
static void __clrex(void)
Performs a clrex operation.
Definition: synchronization.h:52
void RecursiveLock_Lock(RecursiveLock *lock)
Locks a recursive lock.
int64_t s64
64-bit signed integer
Definition: types.h:29
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
int16_t s16
16-bit signed integer
Definition: types.h:27
s32 Result
Function result.
Definition: types.h:42
uint16_t u16
16-bit unsigned integer
Definition: types.h:22
int32_t s32
32-bit signed integer
Definition: types.h:28