Fix sleep issue (freeze) when InputRedirection is enabled
This commit is contained in:
parent
2127271b33
commit
bec8daf028
31
sysmodules/rosalina/include/sleep.h
Normal file
31
sysmodules/rosalina/include/sleep.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2016-2018 Aurora Wright, TuxSH
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
void Sleep__Init(void);
|
||||||
|
void Sleep__HandleNotification(u32 notifId);
|
||||||
|
bool Sleep__Status(void);
|
@ -89,7 +89,8 @@ typedef struct sock_server
|
|||||||
Handle shall_terminate_event;
|
Handle shall_terminate_event;
|
||||||
} sock_server;
|
} sock_server;
|
||||||
|
|
||||||
Result server_init(struct sock_server *serv);
|
Result server_init(struct sock_server *serv);
|
||||||
void server_bind(struct sock_server *serv, u16 port);
|
void server_bind(struct sock_server *serv, u16 port);
|
||||||
void server_run(struct sock_server *serv);
|
void server_run(struct sock_server *serv);
|
||||||
void server_finalize(struct sock_server *serv);
|
void server_finalize(struct sock_server *serv);
|
||||||
|
bool Wifi__IsConnected(void);
|
@ -31,6 +31,8 @@
|
|||||||
#include "input_redirection.h"
|
#include "input_redirection.h"
|
||||||
#include "menus.h"
|
#include "menus.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
#include "sleep.h"
|
||||||
|
#include "sock_util.h"
|
||||||
|
|
||||||
bool inputRedirectionEnabled = false;
|
bool inputRedirectionEnabled = false;
|
||||||
Handle inputRedirectionThreadStartedEvent;
|
Handle inputRedirectionThreadStartedEvent;
|
||||||
@ -96,6 +98,13 @@ void inputRedirectionThreadMain(void)
|
|||||||
pfd.events = POLLIN;
|
pfd.events = POLLIN;
|
||||||
pfd.revents = 0;
|
pfd.revents = 0;
|
||||||
|
|
||||||
|
if (Sleep__Status())
|
||||||
|
{
|
||||||
|
while (!Wifi__IsConnected()
|
||||||
|
&& inputRedirectionEnabled && !terminationRequest)
|
||||||
|
svcSleepThread(1000000000ULL);
|
||||||
|
}
|
||||||
|
|
||||||
int pollres = socPoll(&pfd, 1, 10);
|
int pollres = socPoll(&pfd, 1, 10);
|
||||||
if(pollres > 0 && (pfd.revents & POLLIN))
|
if(pollres > 0 && (pfd.revents & POLLIN))
|
||||||
{
|
{
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "errdisp.h"
|
#include "errdisp.h"
|
||||||
#include "hbloader.h"
|
#include "hbloader.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "sleep.h"
|
||||||
#include "MyThread.h"
|
#include "MyThread.h"
|
||||||
#include "menus/process_patches.h"
|
#include "menus/process_patches.h"
|
||||||
#include "menus/miscellaneous.h"
|
#include "menus/miscellaneous.h"
|
||||||
@ -49,6 +50,7 @@ void __appInit()
|
|||||||
// this is called after main exits
|
// this is called after main exits
|
||||||
void __appExit()
|
void __appExit()
|
||||||
{
|
{
|
||||||
|
acExit();
|
||||||
fsExit();
|
fsExit();
|
||||||
fsregExit();
|
fsregExit();
|
||||||
srvSysExit();
|
srvSysExit();
|
||||||
@ -117,6 +119,8 @@ int main(void)
|
|||||||
if(R_FAILED(svcCreateEvent(&terminationRequestEvent, RESET_STICKY)))
|
if(R_FAILED(svcCreateEvent(&terminationRequestEvent, RESET_STICKY)))
|
||||||
svcBreak(USERBREAK_ASSERT);
|
svcBreak(USERBREAK_ASSERT);
|
||||||
|
|
||||||
|
Sleep__Init();
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
res = svcWaitSynchronization(notificationHandle, -1LL);
|
res = svcWaitSynchronization(notificationHandle, -1LL);
|
||||||
@ -135,6 +139,8 @@ int main(void)
|
|||||||
terminationRequest = true;
|
terminationRequest = true;
|
||||||
svcSignalEvent(terminationRequestEvent);
|
svcSignalEvent(terminationRequestEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Sleep__HandleNotification(notifId);
|
||||||
}
|
}
|
||||||
while(!terminationRequest);
|
while(!terminationRequest);
|
||||||
|
|
||||||
|
62
sysmodules/rosalina/source/sleep.c
Normal file
62
sysmodules/rosalina/source/sleep.c
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2016-2018 Aurora Wright, TuxSH
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <3ds.h>
|
||||||
|
|
||||||
|
static bool g_isSleeping = false;
|
||||||
|
static LightEvent g_onWakeUpEvent;
|
||||||
|
|
||||||
|
void Sleep__Init(void)
|
||||||
|
{
|
||||||
|
srvSubscribe(0x214); ///< Sleep entry
|
||||||
|
srvSubscribe(0x213); ///< Sleep exit
|
||||||
|
LightEvent_Init(&g_onWakeUpEvent, RESET_STICKY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sleep__HandleNotification(u32 notifId)
|
||||||
|
{
|
||||||
|
if (notifId == 0x214) ///< Sleep entry
|
||||||
|
{
|
||||||
|
LightEvent_Clear(&g_onWakeUpEvent);
|
||||||
|
g_isSleeping = true;
|
||||||
|
}
|
||||||
|
else if (notifId == 0x213) ///< Sleep exit
|
||||||
|
{
|
||||||
|
g_isSleeping = false;
|
||||||
|
LightEvent_Signal(&g_onWakeUpEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Sleep__Status(void)
|
||||||
|
{
|
||||||
|
if (g_isSleeping)
|
||||||
|
{
|
||||||
|
LightEvent_Wait(&g_onWakeUpEvent);
|
||||||
|
svcSleepThread(1000000000ULL);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
@ -28,10 +28,12 @@
|
|||||||
#include <3ds/result.h>
|
#include <3ds/result.h>
|
||||||
#include <3ds/svc.h>
|
#include <3ds/svc.h>
|
||||||
#include <3ds/synchronization.h>
|
#include <3ds/synchronization.h>
|
||||||
|
#include <3ds/services/ac.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "minisoc.h"
|
#include "minisoc.h"
|
||||||
#include "sock_util.h"
|
#include "sock_util.h"
|
||||||
|
#include "sleep.h"
|
||||||
|
|
||||||
extern Handle terminationRequestEvent;
|
extern Handle terminationRequestEvent;
|
||||||
extern bool terminationRequest;
|
extern bool terminationRequest;
|
||||||
@ -187,6 +189,14 @@ void server_run(struct sock_server *serv)
|
|||||||
|
|
||||||
for(nfds_t i = 0; i < serv->nfds; i++)
|
for(nfds_t i = 0; i < serv->nfds; i++)
|
||||||
fds[i].revents = 0;
|
fds[i].revents = 0;
|
||||||
|
|
||||||
|
if (Sleep__Status())
|
||||||
|
{
|
||||||
|
while (!Wifi__IsConnected()
|
||||||
|
&& serv->running && !terminationRequest)
|
||||||
|
svcSleepThread(1000000000ULL);
|
||||||
|
}
|
||||||
|
|
||||||
int pollres = socPoll(fds, serv->nfds, 50);
|
int pollres = socPoll(fds, serv->nfds, 50);
|
||||||
|
|
||||||
for(nfds_t i = 0; pollres > 0 && i < serv->nfds; i++)
|
for(nfds_t i = 0; pollres > 0 && i < serv->nfds; i++)
|
||||||
@ -292,3 +302,13 @@ void server_finalize(struct sock_server *serv)
|
|||||||
svcClearEvent(serv->started_event);
|
svcClearEvent(serv->started_event);
|
||||||
svcCloseHandle(serv->started_event);
|
svcCloseHandle(serv->started_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Wifi__IsConnected(void)
|
||||||
|
{
|
||||||
|
u32 status = 0;
|
||||||
|
u32 wifistatus = 0;
|
||||||
|
|
||||||
|
acInit();
|
||||||
|
return R_SUCCEEDED(ACU_GetWifiStatus(&wifistatus)) && wifistatus > 0
|
||||||
|
&& R_SUCCEEDED(ACU_GetStatus(&status)) && status != 1;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user