2018-11-10 09:54:12 +01:00
|
|
|
/*
|
2021-10-04 21:59:10 +02:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2018-11-10 09:54:12 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope 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/>.
|
|
|
|
*/
|
2020-05-12 00:02:10 +02:00
|
|
|
#include <stratosphere.hpp>
|
2018-11-10 09:54:12 +01:00
|
|
|
#include "fatal_task.hpp"
|
|
|
|
|
2018-11-10 10:04:40 +01:00
|
|
|
#include "fatal_task_error_report.hpp"
|
2018-11-10 12:16:13 +01:00
|
|
|
#include "fatal_task_screen.hpp"
|
2018-11-10 12:51:19 +01:00
|
|
|
#include "fatal_task_sound.hpp"
|
2018-11-10 12:05:14 +01:00
|
|
|
#include "fatal_task_clock.hpp"
|
2018-11-10 10:19:52 +01:00
|
|
|
#include "fatal_task_power.hpp"
|
2018-11-10 10:04:40 +01:00
|
|
|
|
2019-10-24 11:30:10 +02:00
|
|
|
namespace ams::fatal::srv {
|
2018-11-10 10:04:40 +01:00
|
|
|
|
2019-07-19 04:09:35 +02:00
|
|
|
namespace {
|
2018-11-10 09:54:12 +01:00
|
|
|
|
2019-07-19 04:09:35 +02:00
|
|
|
class TaskThread {
|
|
|
|
NON_COPYABLE(TaskThread);
|
|
|
|
private:
|
2020-04-08 11:21:35 +02:00
|
|
|
os::ThreadType thread;
|
2019-07-19 04:09:35 +02:00
|
|
|
private:
|
|
|
|
static void RunTaskImpl(void *arg) {
|
|
|
|
ITask *task = reinterpret_cast<ITask *>(arg);
|
2018-11-10 09:54:12 +01:00
|
|
|
|
2019-07-19 04:09:35 +02:00
|
|
|
if (R_FAILED(task->Run())) {
|
|
|
|
/* TODO: Log task failure, somehow? */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
TaskThread() { /* ... */ }
|
|
|
|
void StartTask(ITask *task) {
|
2020-04-17 10:06:07 +02:00
|
|
|
R_ABORT_UNLESS(os::CreateThread(std::addressof(this->thread), RunTaskImpl, task, task->GetStack(), task->GetStackSize(), AMS_GET_SYSTEM_THREAD_PRIORITY(fatalsrv, FatalTaskThread), 3));
|
|
|
|
os::SetThreadNamePointer(std::addressof(this->thread), AMS_GET_SYSTEM_THREAD_NAME(fatalsrv, FatalTaskThread));
|
2020-04-08 11:21:35 +02:00
|
|
|
os::StartThread(std::addressof(this->thread));
|
2019-07-19 04:09:35 +02:00
|
|
|
}
|
|
|
|
};
|
2019-06-18 01:41:03 +02:00
|
|
|
|
2019-07-19 04:09:35 +02:00
|
|
|
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) {
|
2020-02-23 08:05:14 +01:00
|
|
|
AMS_ABORT_UNLESS(this->task_count < MaxTasks);
|
2019-07-19 04:09:35 +02:00
|
|
|
this->task_threads[this->task_count++].StartTask(task);
|
|
|
|
}
|
|
|
|
};
|
2018-11-10 09:54:12 +01:00
|
|
|
|
2019-07-19 04:09:35 +02:00
|
|
|
/* Global task manager. */
|
|
|
|
TaskManager g_task_manager;
|
2019-06-18 01:41:03 +02:00
|
|
|
|
2019-07-19 04:09:35 +02:00
|
|
|
}
|
2019-06-18 01:41:03 +02:00
|
|
|
|
2019-07-19 04:09:35 +02:00
|
|
|
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));
|
|
|
|
}
|
2018-11-10 09:54:12 +01:00
|
|
|
|
|
|
|
}
|