From d8061f67bd2f5d5c2cdfb53287a25eb31a24bd50 Mon Sep 17 00:00:00 2001 From: plutoo Date: Sat, 13 Jan 2018 00:27:47 +0100 Subject: [PATCH] Introduce svcWaitForSynchronizationSingle to clean up code --- nx/include/switch/kernel/svc.h | 5 +++++ nx/source/gfx/gfx.c | 8 +++++--- nx/source/kernel/thread.c | 4 +--- nx/source/runtime/devices/usb_comms.c | 6 ++---- nx/source/services/applet.c | 10 ++++------ nx/source/services/usb.c | 9 ++++----- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/nx/include/switch/kernel/svc.h b/nx/include/switch/kernel/svc.h index 1817f517..e2d125d0 100644 --- a/nx/include/switch/kernel/svc.h +++ b/nx/include/switch/kernel/svc.h @@ -81,3 +81,8 @@ Result svcMapProcessMemory(void* dst, Handle proc, u64 src, u64 size); Result svcCreateProcess(Handle* out, void* proc_info, u32* caps, u64 cap_num); Result svcStartProcess(Handle proc, s32 main_prio, s32 default_cpu, u32 stack_size); u64 svcCallSecureMonitor(SecmonArgs* regs); + +static inline Result svcWaitSynchronizationSingle(Handle handle, u64 timeout) { + s32 tmp; + return svcWaitSynchronization(&tmp, &handle, 1, timeout); +} diff --git a/nx/source/gfx/gfx.c b/nx/source/gfx/gfx.c index 241a6d47..a84a01e7 100644 --- a/nx/source/gfx/gfx.c +++ b/nx/source/gfx/gfx.c @@ -451,14 +451,16 @@ Result _gfxGraphicBufferInit(s32 buf, u32 nvmap_handle) { } static void _waitevent(Handle *handle) { - s32 tmpindex=0; Result rc=0, rc2=0; svcResetSignal(*handle); do { - rc = svcWaitSynchronization(&tmpindex, handle, 1, U64_MAX); - if (R_SUCCEEDED(rc)) rc2 = svcResetSignal(*handle); + rc = svcWaitSynchronizationSingle(*handle, U64_MAX); + + if (R_SUCCEEDED(rc)) + rc2 = svcResetSignal(*handle); + } while(R_FAILED(rc) || (rc2 & 0x3FFFFF)==0xFA01); if (R_FAILED(rc2)) fatalSimple(rc2); diff --git a/nx/source/kernel/thread.c b/nx/source/kernel/thread.c index 34ee124a..62efccc3 100644 --- a/nx/source/kernel/thread.c +++ b/nx/source/kernel/thread.c @@ -109,9 +109,7 @@ Result threadStart(Thread* t) { } Result threadWaitForExit(Thread* t) { - Handle handle = t->handle; - s32 idx = 0; - return svcWaitSynchronization(&idx, &handle, 1, -1); + return svcWaitSynchronizationSingle(t->handle, -1); } Result threadClose(Thread* t) { diff --git a/nx/source/runtime/devices/usb_comms.c b/nx/source/runtime/devices/usb_comms.c index 6a7c9615..4932c398 100644 --- a/nx/source/runtime/devices/usb_comms.c +++ b/nx/source/runtime/devices/usb_comms.c @@ -139,7 +139,6 @@ static Result _usbCommsRead(void* buffer, size_t size, size_t *transferredSize) u8 *bufptr = (u8*)buffer; u8 *transfer_buffer = NULL; u8 transfer_type=0; - s32 tmpindex=0; u32 chunksize=0; u32 tmp_transferredSize = 0; size_t total_transferredSize=0; @@ -175,7 +174,7 @@ static Result _usbCommsRead(void* buffer, size_t size, size_t *transferredSize) if (R_FAILED(ret)) return ret; //Wait for the transfer to finish. - svcWaitSynchronization(&tmpindex, &g_usbComms_endpoint_out->CompletionEvent, 1, U64_MAX); + svcWaitSynchronizationSingle(g_usbComms_endpoint_out->CompletionEvent, U64_MAX); svcClearEvent(g_usbComms_endpoint_out->CompletionEvent); ret = usbDsEndpoint_GetReportData(g_usbComms_endpoint_out, &reportdata); @@ -206,7 +205,6 @@ static Result _usbCommsWrite(const void* buffer, size_t size, size_t *transferre u32 chunksize=0; u8 *bufptr = (u8*)buffer; u8 *transfer_buffer = NULL; - s32 tmpindex=0; u32 tmp_transferredSize = 0; size_t total_transferredSize=0; usbDsReportData reportdata; @@ -239,7 +237,7 @@ static Result _usbCommsWrite(const void* buffer, size_t size, size_t *transferre if(R_FAILED(ret))return ret; //Wait for the transfer to finish. - svcWaitSynchronization(&tmpindex, &g_usbComms_endpoint_in->CompletionEvent, 1, U64_MAX); + svcWaitSynchronizationSingle(g_usbComms_endpoint_in->CompletionEvent, U64_MAX); svcClearEvent(g_usbComms_endpoint_in->CompletionEvent); ret = usbDsEndpoint_GetReportData(g_usbComms_endpoint_in, &reportdata); diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index 63d0e8eb..0ee64bd1 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -142,8 +142,7 @@ Result appletInitialize(void) if (R_SUCCEEDED(rc)) { do { - s32 tmp_index=0; - svcWaitSynchronization(&tmp_index, &g_appletMessageEventHandle, 1, U64_MAX); + svcWaitSynchronizationSingle(g_appletMessageEventHandle, U64_MAX); u32 msg; rc = _appletReceiveMessage(&msg); @@ -839,11 +838,10 @@ u8 appletGetFocusState(void) { } bool appletMainLoop(void) { - Result rc=0; - u32 msg=0; - s32 tmpindex=0; + Result rc; + u32 msg = 0; - if (R_FAILED(svcWaitSynchronization(&tmpindex, &g_appletMessageEventHandle, 1, 0))) + if (R_FAILED(svcWaitSynchronizationSingle(g_appletMessageEventHandle, 0))) return true; rc = _appletReceiveMessage(&msg); diff --git a/nx/source/services/usb.c b/nx/source/services/usb.c index 864640a1..f28207f7 100644 --- a/nx/source/services/usb.c +++ b/nx/source/services/usb.c @@ -299,16 +299,15 @@ Result usbDsGetState(u32 *out) { } Result usbDsWaitReady(void) { - Result rc = 0; - u32 state=0; - s32 tmpindex = 0; + Result rc; + u32 state = 0; rc = usbDsGetState(&state); if (R_FAILED(rc)) return rc; - while(R_SUCCEEDED(rc) && state!=5) + while (R_SUCCEEDED(rc) && state != 5) { - svcWaitSynchronization(&tmpindex, &g_usbDsStateChangeEvent, 1, U64_MAX); + svcWaitSynchronizationSingle(g_usbDsStateChangeEvent, U64_MAX); svcClearEvent(g_usbDsStateChangeEvent); rc = usbDsGetState(&state); }