mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-13 22:54:24 -04:00
fatal: refactor into sts namespace
This commit is contained in:
parent
442ebff829
commit
39d041466d
38 changed files with 2176 additions and 1926 deletions
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include "fatal_types.hpp"
|
||||
|
||||
#include "fatal_task.hpp"
|
||||
|
||||
#include "fatal_task_error_report.hpp"
|
||||
|
@ -24,40 +24,64 @@
|
|||
#include "fatal_task_clock.hpp"
|
||||
#include "fatal_task_power.hpp"
|
||||
|
||||
namespace sts::fatal::srv {
|
||||
|
||||
static constexpr size_t MaxTasks = 8;
|
||||
static HosThread g_task_threads[MaxTasks];
|
||||
static size_t g_num_threads = 0;
|
||||
namespace {
|
||||
|
||||
class TaskThread {
|
||||
NON_COPYABLE(TaskThread);
|
||||
private:
|
||||
static constexpr int TaskThreadPriority = 15;
|
||||
private:
|
||||
HosThread thread;
|
||||
private:
|
||||
static void RunTaskImpl(void *arg) {
|
||||
ITask *task = reinterpret_cast<ITask *>(arg);
|
||||
|
||||
static void RunTaskThreadFunc(void *arg) {
|
||||
IFatalTask *task = reinterpret_cast<IFatalTask *>(arg);
|
||||
if (R_FAILED(task->Run())) {
|
||||
/* TODO: Log task failure, somehow? */
|
||||
}
|
||||
}
|
||||
public:
|
||||
TaskThread() { /* ... */ }
|
||||
void StartTask(ITask *task) {
|
||||
R_ASSERT(this->thread.Initialize(&RunTaskImpl, task, task->GetStackSize(), TaskThreadPriority));
|
||||
R_ASSERT(this->thread.Start());
|
||||
}
|
||||
};
|
||||
|
||||
class TaskManager {
|
||||
NON_COPYABLE(TaskManager);
|
||||
private:
|
||||
static constexpr size_t MaxTasks = 8;
|
||||
private:
|
||||
TaskThread task_threads[MaxTasks];
|
||||
size_t task_count = 0;
|
||||
public:
|
||||
TaskManager() { /* ... */ }
|
||||
void StartTask(ITask *task) {
|
||||
if (this->task_count >= MaxTasks) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
this->task_threads[this->task_count++].StartTask(task);
|
||||
}
|
||||
};
|
||||
|
||||
/* Global task manager. */
|
||||
TaskManager g_task_manager;
|
||||
|
||||
if (R_FAILED(task->Run())) {
|
||||
/* TODO: Log task failure, somehow? */
|
||||
}
|
||||
|
||||
/* Finish. */
|
||||
}
|
||||
|
||||
static void RunTask(IFatalTask *task, u32 stack_size = 0x4000) {
|
||||
if (g_num_threads >= MaxTasks) {
|
||||
std::abort();
|
||||
void RunTasks(const ThrowContext *ctx) {
|
||||
g_task_manager.StartTask(GetErrorReportTask(ctx));
|
||||
g_task_manager.StartTask(GetPowerControlTask(ctx));
|
||||
g_task_manager.StartTask(GetShowFatalTask(ctx));
|
||||
g_task_manager.StartTask(GetStopSoundTask(ctx));
|
||||
g_task_manager.StartTask(GetBacklightControlTask(ctx));
|
||||
g_task_manager.StartTask(GetAdjustClockTask(ctx));
|
||||
g_task_manager.StartTask(GetPowerButtonObserveTask(ctx));
|
||||
g_task_manager.StartTask(GetStateTransitionStopTask(ctx));
|
||||
}
|
||||
|
||||
HosThread *cur_thread = &g_task_threads[g_num_threads++];
|
||||
|
||||
cur_thread->Initialize(&RunTaskThreadFunc, task, stack_size, 15);
|
||||
cur_thread->Start();
|
||||
}
|
||||
|
||||
void RunFatalTasks(FatalThrowContext *ctx, u64 title_id, bool error_report, Event *erpt_event, Event *battery_event) {
|
||||
RunTask(new ErrorReportTask(ctx, title_id, error_report, erpt_event));
|
||||
RunTask(new PowerControlTask(ctx, title_id, erpt_event, battery_event));
|
||||
RunTask(new ShowFatalTask(ctx, title_id, battery_event), 0x10000);
|
||||
RunTask(new StopSoundTask(ctx, title_id));
|
||||
RunTask(new BacklightControlTask(ctx, title_id));
|
||||
RunTask(new AdjustClockTask(ctx, title_id));
|
||||
RunTask(new PowerButtonObserveTask(ctx, title_id, erpt_event));
|
||||
RunTask(new StateTransitionStopTask(ctx, title_id));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue