Add, document, and use MAX_WAIT_OBJECTS

This commit is contained in:
fincs 2018-12-15 18:11:35 +01:00 committed by fincs
parent 33dad9b893
commit 21f69bfa57
3 changed files with 7 additions and 5 deletions

View File

@ -13,6 +13,9 @@
/// Pseudo handle for the current thread.
#define CUR_THREAD_HANDLE 0xFFFF8000
/// Maximum number of objects that can be waited on by \ref svcWaitSynchronization (Horizon kernel limitation).
#define MAX_WAIT_OBJECTS 0x40
/// Memory type enumeration (lower 8 bits of \ref MemoryState)
typedef enum {
MemType_Unmapped=0x00, ///< Unmapped memory.
@ -362,6 +365,7 @@ Result svcResetSignal(Handle handle);
* @brief Waits on one or more synchronization objects, optionally with a timeout.
* @return Result code.
* @note Syscall number 0x18.
* @note \p handleCount must not be greater than \ref MAX_WAIT_OBJECTS. This is a Horizon kernel limitation.
* @note Please use \ref waitMultiHandle instead. That function handles sporadical interrupts caused by usermode synchronization primitives.
*/
Result svcWaitSynchronization(s32* index, const Handle* handles, s32 handleCount, u64 timeout);

View File

@ -58,7 +58,7 @@ Result waitNHandle(s32* idx_out, Handle* handles, size_t num_handles, u64 timeou
* @brief Waits for an arbitrary number of waiters. This is a macro that uses var-args.
* @param[out] idx_out The index of the signalled waiter.
* @param[in] timeout Timeout (in nanoseconds).
* @note The number of waiters must be less than 64. This is a Horizon kernel limitation.
* @note The number of objects must not be greater than \ref MAX_WAIT_OBJECTS. This is a Horizon kernel limitation.
*/
#define waitMulti(idx_out, timeout, ...) \
waitN((idx_out), (Waiter[]) { __VA_ARGS__ }, sizeof((Waiter[]) { __VA_ARGS__ }) / sizeof(Waiter), (timeout))
@ -67,7 +67,7 @@ Result waitNHandle(s32* idx_out, Handle* handles, size_t num_handles, u64 timeou
* @brief Waits for an arbitrary number of handles. This is a macro that uses var-args.
* @param[out] idx_out The index of the signalled handle.
* @param[in] timeout Timeout (in nanoseconds).
* @note The number of handles must be less than 64. This is a Horizon kernel limitation.
* @note The number of objects must not be greater than \ref MAX_WAIT_OBJECTS. This is a Horizon kernel limitation.
*/
#define waitMultiHandle(idx_out, timeout, ...) \
waitNHandle((idx_out), (Handle[]) { __VA_ARGS__ }, sizeof((Handle[]) { __VA_ARGS__ }) / sizeof(Handle), (timeout))

View File

@ -8,13 +8,11 @@
#include "wait.h"
#include "../internal.h"
#define MAX_WAIT 0x40
typedef Result (*WaitImplFunc)(s32* idx_out, void* objects, size_t num_objects, u64 timeout);
static Result waitImpl(s32* idx_out, Waiter* objects, size_t num_objects, u64 timeout)
{
if (num_objects > MAX_WAIT)
if (num_objects > MAX_WAIT_OBJECTS)
return KERNELRESULT(OutOfRange); // same error returned by kernel
Handle own_thread_handle = getThreadVars()->handle;