libctru  v1.6.0
Data Structures | Macros | Typedefs | Functions
synchronization.h File Reference

Provides synchronization locks. More...

#include <sys/lock.h>
#include <3ds/svc.h>

Go to the source code of this file.

Data Structures

struct  LightEvent
 A light event. More...
 
struct  LightSemaphore
 A light semaphore. More...
 

Macros

#define AtomicIncrement(ptr)   __atomic_add_fetch((u32*)(ptr), 1, __ATOMIC_SEQ_CST)
 Performs an atomic pre-increment operation.
 
#define AtomicDecrement(ptr)   __atomic_sub_fetch((u32*)(ptr), 1, __ATOMIC_SEQ_CST)
 Performs an atomic pre-decrement operation.
 
#define AtomicPostIncrement(ptr)   __atomic_fetch_add((u32*)(ptr), 1, __ATOMIC_SEQ_CST)
 Performs an atomic post-increment operation.
 
#define AtomicPostDecrement(ptr)   __atomic_fetch_sub((u32*)(ptr), 1, __ATOMIC_SEQ_CST)
 Performs an atomic post-decrement operation.
 
#define AtomicSwap(ptr, value)   __atomic_exchange_n((u32*)(ptr), (value), __ATOMIC_SEQ_CST)
 Performs an atomic swap operation.
 

Typedefs

typedef _LOCK_T LightLock
 A light lock.
 
typedef _LOCK_RECURSIVE_T RecursiveLock
 A recursive lock.
 

Functions

static void __dsb (void)
 Performs a Data Synchronization Barrier operation.
 
static void __clrex (void)
 Performs a clrex operation.
 
static s32 __ldrex (s32 *addr)
 Performs a ldrex operation. More...
 
static bool __strex (s32 *addr, s32 val)
 Performs a strex operation. More...
 
static u16 __ldrexh (u16 *addr)
 Performs a ldrexh operation. More...
 
static bool __strexh (u16 *addr, u16 val)
 Performs a strexh operation. More...
 
static u8 __ldrexb (u8 *addr)
 Performs a ldrexb operation. More...
 
static bool __strexb (u8 *addr, u8 val)
 Performs a strexb operation. More...
 
Handle __sync_get_arbiter (void)
 Retrieves the synchronization subsystem's address arbiter handle. More...
 
void LightLock_Init (LightLock *lock)
 Initializes a light lock. More...
 
void LightLock_Lock (LightLock *lock)
 Locks a light lock. More...
 
int LightLock_TryLock (LightLock *lock)
 Attempts to lock a light lock. More...
 
void LightLock_Unlock (LightLock *lock)
 Unlocks a light lock. More...
 
void RecursiveLock_Init (RecursiveLock *lock)
 Initializes a recursive lock. More...
 
void RecursiveLock_Lock (RecursiveLock *lock)
 Locks a recursive lock. More...
 
int RecursiveLock_TryLock (RecursiveLock *lock)
 Attempts to lock a recursive lock. More...
 
void RecursiveLock_Unlock (RecursiveLock *lock)
 Unlocks a recursive lock. More...
 
void LightEvent_Init (LightEvent *event, ResetType reset_type)
 Initializes a light event. More...
 
void LightEvent_Clear (LightEvent *event)
 Clears a light event. More...
 
void LightEvent_Pulse (LightEvent *event)
 Wakes up threads waiting on a sticky light event without signaling it. More...
 
void LightEvent_Signal (LightEvent *event)
 Signals a light event, waking up threads waiting on it. More...
 
int LightEvent_TryWait (LightEvent *event)
 Attempts to wait on a light event. More...
 
void LightEvent_Wait (LightEvent *event)
 Waits on a light event. More...
 
void LightSemaphore_Init (LightSemaphore *semaphore, s16 initial_count, s16 max_count)
 Initializes a light semaphore. More...
 
void LightSemaphore_Acquire (LightSemaphore *semaphore, s32 count)
 Acquires a light semaphore. More...
 
void LightSemaphore_Release (LightSemaphore *semaphore, s32 count)
 Releases a light semaphore. More...
 

Detailed Description

Provides synchronization locks.

Function Documentation

◆ __ldrex()

static s32 __ldrex ( s32 addr)
inlinestatic

Performs a ldrex operation.

Parameters
addrAddress to perform the operation on.
Returns
The resulting value.

◆ __ldrexb()

static u8 __ldrexb ( u8 addr)
inlinestatic

Performs a ldrexb operation.

Parameters
addrAddress to perform the operation on.
Returns
The resulting value.

◆ __ldrexh()

static u16 __ldrexh ( u16 addr)
inlinestatic

Performs a ldrexh operation.

Parameters
addrAddress to perform the operation on.
Returns
The resulting value.

◆ __strex()

static bool __strex ( s32 addr,
s32  val 
)
inlinestatic

Performs a strex operation.

Parameters
addrAddress to perform the operation on.
valValue to store.
Returns
Whether the operation was successful.

◆ __strexb()

static bool __strexb ( u8 addr,
u8  val 
)
inlinestatic

Performs a strexb operation.

Parameters
addrAddress to perform the operation on.
valValue to store.
Returns
Whether the operation was successful.

◆ __strexh()

static bool __strexh ( u16 addr,
u16  val 
)
inlinestatic

Performs a strexh operation.

Parameters
addrAddress to perform the operation on.
valValue to store.
Returns
Whether the operation was successful.

◆ __sync_get_arbiter()

Handle __sync_get_arbiter ( void  )

Retrieves the synchronization subsystem's address arbiter handle.

Returns
The synchronization subsystem's address arbiter handle.

◆ LightEvent_Clear()

void LightEvent_Clear ( LightEvent event)

Clears a light event.

Parameters
eventPointer to the event.

◆ LightEvent_Init()

void LightEvent_Init ( LightEvent event,
ResetType  reset_type 
)

Initializes a light event.

Parameters
eventPointer to the event.
reset_typeType of reset the event uses (RESET_ONESHOT/RESET_STICKY).

◆ LightEvent_Pulse()

void LightEvent_Pulse ( LightEvent event)

Wakes up threads waiting on a sticky light event without signaling it.

If the event had been signaled before, it is cleared instead.

Parameters
eventPointer to the event.

◆ LightEvent_Signal()

void LightEvent_Signal ( LightEvent event)

Signals a light event, waking up threads waiting on it.

Parameters
eventPointer to the event.

◆ LightEvent_TryWait()

int LightEvent_TryWait ( LightEvent event)

Attempts to wait on a light event.

Parameters
eventPointer to the event.
Returns
Non-zero if the event was signaled, zero otherwise.

◆ LightEvent_Wait()

void LightEvent_Wait ( LightEvent event)

Waits on a light event.

Parameters
eventPointer to the event.

◆ LightLock_Init()

void LightLock_Init ( LightLock lock)

Initializes a light lock.

Parameters
lockPointer to the lock.

◆ LightLock_Lock()

void LightLock_Lock ( LightLock lock)

Locks a light lock.

Parameters
lockPointer to the lock.

◆ LightLock_TryLock()

int LightLock_TryLock ( LightLock lock)

Attempts to lock a light lock.

Parameters
lockPointer to the lock.
Returns
Zero on success, non-zero on failure.

◆ LightLock_Unlock()

void LightLock_Unlock ( LightLock lock)

Unlocks a light lock.

Parameters
lockPointer to the lock.

◆ LightSemaphore_Acquire()

void LightSemaphore_Acquire ( LightSemaphore semaphore,
s32  count 
)

Acquires a light semaphore.

Parameters
semaphorePointer to the semaphore.
countAcquire count

◆ LightSemaphore_Init()

void LightSemaphore_Init ( LightSemaphore semaphore,
s16  initial_count,
s16  max_count 
)

Initializes a light semaphore.

Parameters
eventPointer to the semaphore.
max_countInitial count of the semaphore.
max_countMaximum count of the semaphore.

◆ LightSemaphore_Release()

void LightSemaphore_Release ( LightSemaphore semaphore,
s32  count 
)

Releases a light semaphore.

Parameters
semaphorePointer to the semaphore.
countRelease count

◆ RecursiveLock_Init()

void RecursiveLock_Init ( RecursiveLock lock)

Initializes a recursive lock.

Parameters
lockPointer to the lock.

◆ RecursiveLock_Lock()

void RecursiveLock_Lock ( RecursiveLock lock)

Locks a recursive lock.

Parameters
lockPointer to the lock.

◆ RecursiveLock_TryLock()

int RecursiveLock_TryLock ( RecursiveLock lock)

Attempts to lock a recursive lock.

Parameters
lockPointer to the lock.
Returns
Zero on success, non-zero on failure.

◆ RecursiveLock_Unlock()

void RecursiveLock_Unlock ( RecursiveLock lock)

Unlocks a recursive lock.

Parameters
lockPointer to the lock.