mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 20:42:44 +02:00
usbDsWaitReady: use deadline timeout
This commit is contained in:
parent
f82d97f88a
commit
1e9fe9b199
@ -4,6 +4,7 @@
|
|||||||
#include "services/usbds.h"
|
#include "services/usbds.h"
|
||||||
#include "runtime/hosversion.h"
|
#include "runtime/hosversion.h"
|
||||||
#include "runtime/util/utf.h"
|
#include "runtime/util/utf.h"
|
||||||
|
#include "switch/arm/counter.h"
|
||||||
|
|
||||||
#define TOTAL_INTERFACES 4
|
#define TOTAL_INTERFACES 4
|
||||||
#define TOTAL_ENDPOINTS_IN 16
|
#define TOTAL_ENDPOINTS_IN 16
|
||||||
@ -234,12 +235,27 @@ Result usbDsWaitReady(u64 timeout) {
|
|||||||
|
|
||||||
rc = usbDsGetState(&state);
|
rc = usbDsGetState(&state);
|
||||||
if (R_FAILED(rc)) return rc;
|
if (R_FAILED(rc)) return rc;
|
||||||
|
if (state == UsbState_Configured) return 0;
|
||||||
|
|
||||||
|
bool has_timeout = timeout != UINT64_MAX;
|
||||||
|
u64 deadline = 0;
|
||||||
|
|
||||||
|
if (has_timeout)
|
||||||
|
deadline = armGetSystemTick() + armNsToTicks(timeout);
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (has_timeout) {
|
||||||
|
s64 remaining = deadline - armGetSystemTick();
|
||||||
|
timeout = remaining > 0 ? armTicksToNs(remaining) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
while (R_SUCCEEDED(rc) && state != UsbState_Configured) {
|
|
||||||
eventWait(&g_usbDsStateChangeEvent, timeout);
|
eventWait(&g_usbDsStateChangeEvent, timeout);
|
||||||
eventClear(&g_usbDsStateChangeEvent);
|
eventClear(&g_usbDsStateChangeEvent);
|
||||||
rc = usbDsGetState(&state);
|
rc = usbDsGetState(&state);
|
||||||
}
|
} while (R_SUCCEEDED(rc) && state != UsbState_Configured && timeout > 0);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc) && state != UsbState_Configured && timeout == 0)
|
||||||
|
return KERNELRESULT(TimedOut);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user