rosalina: make the task runner thread actually exit

This commit is contained in:
TuxSH 2020-04-26 21:37:18 +01:00
parent 1d8b793cf7
commit 9d62995799
5 changed files with 40 additions and 7 deletions

View File

@ -4,6 +4,11 @@
TaskRunner g_taskRunner;
static void taskRunnerNoOpFunction(void *args)
{
(void)args;
}
void TaskRunner_Init(void)
{
memset(&g_taskRunner, 0, sizeof(TaskRunner));
@ -20,12 +25,23 @@ void TaskRunner_RunTask(void (*task)(void *argdata), void *argdata, size_t argsi
LightEvent_Signal(&g_taskRunner.parametersSetEvent);
}
void TaskRunner_Terminate(void)
{
g_taskRunner.shouldTerminate = true;
TaskRunner_RunTask(taskRunnerNoOpFunction, NULL, 0);
}
void TaskRunner_HandleTasks(void *p)
{
(void)p;
for (;;) {
while (!g_taskRunner.shouldTerminate) {
LightEvent_Signal(&g_taskRunner.readyEvent);
LightEvent_Wait(&g_taskRunner.parametersSetEvent);
g_taskRunner.task(g_taskRunner.argStorage);
}
}
void TaskRunner_WaitReady(void)
{
LightEvent_Wait(&g_taskRunner.readyEvent);
}

View File

@ -8,11 +8,15 @@ typedef struct TaskRunner {
LightEvent parametersSetEvent;
void (*task)(void *argdata);
u8 argStorage[0x40];
bool shouldTerminate;
} TaskRunner;
extern TaskRunner g_taskRunner;
void TaskRunner_Init(void);
void TaskRunner_RunTask(void (*task)(void *argdata), void *argdata, size_t argsize);
void TaskRunner_Terminate(void);
/// Thread function
void TaskRunner_HandleTasks(void *p);
void TaskRunner_WaitReady(void);

View File

@ -9,6 +9,7 @@ typedef struct TaskRunner {
LightEvent parametersSetEvent;
void (*task)(void *argdata);
u8 argStorage[0x40];
bool shouldTerminate;
} TaskRunner;
extern TaskRunner g_taskRunner;
@ -17,6 +18,8 @@ MyThread *taskRunnerCreateThread(void);
void TaskRunner_Init(void);
void TaskRunner_RunTask(void (*task)(void *argdata), void *argdata, size_t argsize);
void TaskRunner_Terminate(void);
/// Thread function
void TaskRunner_HandleTasks(void);
void TaskRunner_WaitReady(void);
void TaskRunner_WaitReady(void);

View File

@ -97,7 +97,7 @@ void exit(int rc)
svcCloseHandle(*fsRegGetSessionHandle());
srvExit();
__sync_fini();*/
svcExitProcess();
}
@ -163,10 +163,9 @@ static void handleTermNotification(u32 notificationId)
static void handleNextApplicationDebuggedByForce(u32 notificationId)
{
int dummy;
(void)notificationId;
// Following call needs to be async because pm -> Loader depends on rosalina hb:ldr, handled in this very thread.
TaskRunner_RunTask(debuggerFetchAndSetNextApplicationDebugHandleTask, &dummy, 0);
TaskRunner_RunTask(debuggerFetchAndSetNextApplicationDebugHandleTask, NULL, 0);
}
static const ServiceManagerServiceEntry services[] = {
@ -204,6 +203,8 @@ int main(void)
if (R_FAILED(ServiceManager_Run(services, notifications, NULL)))
svcBreak(USERBREAK_PANIC);
TaskRunner_Terminate();
MyThread_Join(menuThread, -1LL);
MyThread_Join(taskRunnerThread, -1LL);
MyThread_Join(errDispThread, -1LL);

View File

@ -7,7 +7,10 @@ TaskRunner g_taskRunner;
static MyThread taskRunnerThread;
static u8 ALIGN(8) taskRunnerThreadStack[0x1000];
extern bool terminationRequest;
static void taskRunnerNoOpFunction(void *args)
{
(void)args;
}
MyThread *taskRunnerCreateThread(void)
{
@ -32,9 +35,15 @@ void TaskRunner_RunTask(void (*task)(void *argdata), void *argdata, size_t argsi
LightEvent_Signal(&g_taskRunner.parametersSetEvent);
}
void TaskRunner_Terminate(void)
{
g_taskRunner.shouldTerminate = true;
TaskRunner_RunTask(taskRunnerNoOpFunction, NULL, 0);
}
void TaskRunner_HandleTasks(void)
{
while (!terminationRequest) {
while (!g_taskRunner.shouldTerminate) {
LightEvent_Signal(&g_taskRunner.readyEvent);
LightEvent_Wait(&g_taskRunner.parametersSetEvent);
g_taskRunner.task(g_taskRunner.argStorage);