From 19fd446ac576fab8c6c660b34bbf6d65d75be418 Mon Sep 17 00:00:00 2001 From: fincs Date: Tue, 30 Jun 2020 18:45:03 +0200 Subject: [PATCH] Add and use svcArbitrateAddressNoTimeout (minor ABI optimization) --- libctru/include/3ds/svc.h | 17 +++++++++++++++-- libctru/include/3ds/synchronization.h | 4 ++++ libctru/source/svc.s | 5 +++++ libctru/source/synchronization.c | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/libctru/include/3ds/svc.h b/libctru/include/3ds/svc.h index bb061ea..cacedc0 100644 --- a/libctru/include/3ds/svc.h +++ b/libctru/include/3ds/svc.h @@ -915,9 +915,22 @@ Result svcCreateAddressArbiter(Handle *arbiter); * @param addr A pointer to a s32 value. * @param type Type of action to be performed by the arbiter * @param value Number of threads to signal if using @ref ARBITRATION_SIGNAL, or the value used for comparison. - * @warning Please use \ref syncArbitrateAddress or \ref syncArbitrateAddressWithTimeout instead. + * @param timeout_ns Optional timeout in nanoseconds when using TIMEOUT actions, ignored otherwise. If not needed, use \ref svcArbitrateAddressNoTimeout instead. + * @note Usage of this syscall entails an implicit Data Memory Barrier (dmb). + * @warning Please use \ref syncArbitrateAddressWithTimeout instead. */ -Result svcArbitrateAddress(Handle arbiter, u32 addr, ArbitrationType type, s32 value, s64 nanoseconds); +Result svcArbitrateAddress(Handle arbiter, u32 addr, ArbitrationType type, s32 value, s64 timeout_ns); + +/** + * @brief Same as \ref svcArbitrateAddress but with the timeout_ns parameter undefined. + * @param arbiter Handle of the arbiter + * @param addr A pointer to a s32 value. + * @param type Type of action to be performed by the arbiter + * @param value Number of threads to signal if using @ref ARBITRATION_SIGNAL, or the value used for comparison. + * @note Usage of this syscall entails an implicit Data Memory Barrier (dmb). + * @warning Please use \ref syncArbitrateAddress instead. + */ +Result svcArbitrateAddressNoTimeout(Handle arbiter, u32 addr, ArbitrationType type, s32 value); /** * @brief Sends a synchronized request to a session handle. diff --git a/libctru/include/3ds/synchronization.h b/libctru/include/3ds/synchronization.h index 85c2e5c..9ba9339 100755 --- a/libctru/include/3ds/synchronization.h +++ b/libctru/include/3ds/synchronization.h @@ -144,6 +144,8 @@ static inline bool __strexb(u8* addr, u8 val) * // Does *nothing* since val >= 0 * syncArbitrateAddress(&val,ARBITRATION_WAIT_IF_LESS_THAN,0); * @endcode + * + * @note Usage of this function entails an implicit Data Memory Barrier (dmb). */ Result syncArbitrateAddress(s32* addr, ArbitrationType type, s32 value); @@ -160,6 +162,8 @@ Result syncArbitrateAddress(s32* addr, ArbitrationType type, s32 value); * // Thread will wait for a signal or wake up after 10000000 nanoseconds because val < 1. * syncArbitrateAddressWithTimeout(&val,ARBITRATION_WAIT_IF_LESS_THAN_TIMEOUT,1,10000000LL); * @endcode + * + * @note Usage of this function entails an implicit Data Memory Barrier (dmb). */ Result syncArbitrateAddressWithTimeout(s32* addr, ArbitrationType type, s32 value, s64 timeout_ns); diff --git a/libctru/source/svc.s b/libctru/source/svc.s index 408f4d3..aa5c815 100644 --- a/libctru/source/svc.s +++ b/libctru/source/svc.s @@ -249,6 +249,11 @@ SVC_BEGIN svcArbitrateAddress bx lr SVC_END +SVC_BEGIN svcArbitrateAddressNoTimeout + svc 0x22 + bx lr +SVC_END + SVC_BEGIN svcCloseHandle svc 0x23 bx lr diff --git a/libctru/source/synchronization.c b/libctru/source/synchronization.c index 65a387f..14b4f2e 100644 --- a/libctru/source/synchronization.c +++ b/libctru/source/synchronization.c @@ -18,7 +18,7 @@ void __sync_fini(void) Result syncArbitrateAddress(s32* addr, ArbitrationType type, s32 value) { - return svcArbitrateAddress(arbiter, (u32)addr, type, value, 0); + return svcArbitrateAddressNoTimeout(arbiter, (u32)addr, type, value); } Result syncArbitrateAddressWithTimeout(s32* addr, ArbitrationType type, s32 value, s64 timeout_ns)