stratosphere: only hold sm sessions open when needed

This commit is contained in:
Michael Scire 2019-04-22 12:40:53 -07:00
parent c3875796df
commit b09adb6a34
16 changed files with 432 additions and 403 deletions

View file

@ -78,15 +78,17 @@ static bool IsHexadecimal(const char *str) {
void Utils::InitializeThreadFunc(void *args) {
/* Get required services. */
Handle tmp_hnd = 0;
static const char * const required_active_services[] = {"pcv", "gpio", "pinmux", "psc:c"};
for (unsigned int i = 0; i < sizeof(required_active_services) / sizeof(required_active_services[0]); i++) {
if (R_FAILED(smGetServiceOriginal(&tmp_hnd, smEncodeName(required_active_services[i])))) {
/* TODO: Panic */
} else {
svcCloseHandle(tmp_hnd);
DoWithSmSession([&]() {
Handle tmp_hnd = 0;
static const char * const required_active_services[] = {"pcv", "gpio", "pinmux", "psc:c"};
for (unsigned int i = 0; i < sizeof(required_active_services) / sizeof(required_active_services[0]); i++) {
if (R_FAILED(smGetServiceOriginal(&tmp_hnd, smEncodeName(required_active_services[i])))) {
/* TODO: Panic */
} else {
svcCloseHandle(tmp_hnd);
}
}
}
});
/* Mount SD. */
while (R_FAILED(fsMountSdcard(&g_sd_filesystem))) {
@ -197,7 +199,11 @@ void Utils::InitializeThreadFunc(void *args) {
Utils::RefreshConfiguration();
/* Initialize set:sys. */
setsysInitialize();
DoWithSmSession([&]() {
if (R_FAILED(setsysInitialize())) {
std::abort();
}
});
/* Signal SD is initialized. */
g_has_initialized = true;
@ -209,13 +215,15 @@ void Utils::InitializeThreadFunc(void *args) {
g_sd_signal.Signal();
/* Initialize HID. */
{
while (R_FAILED(hidInitialize())) {
while (!g_has_hid_session) {
DoWithSmSession([&]() {
if (R_SUCCEEDED(hidInitialize())) {
g_has_hid_session = true;
}
});
if (!g_has_hid_session) {
svcSleepThread(1000000ULL);
}
g_has_hid_session = true;
}
}