mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-13 06:34:23 -04:00
kern: implement init through InterruptTaskManager.Initialize()
This commit is contained in:
parent
3c78bc4dbf
commit
3bcc4adb5c
8 changed files with 87 additions and 6 deletions
|
@ -18,6 +18,10 @@
|
|||
namespace ams::kern {
|
||||
|
||||
void KInterruptTaskManager::TaskQueue::Enqueue(KInterruptTask *task) {
|
||||
MESOSPHERE_ASSERT(task->GetNextTask() == nullptr);
|
||||
MESOSPHERE_ASSERT(task != this->head);
|
||||
MESOSPHERE_ASSERT(task != this->tail);
|
||||
|
||||
/* Insert the task into the queue. */
|
||||
if (this->tail != nullptr) {
|
||||
this->tail->SetNextTask(task);
|
||||
|
@ -29,6 +33,10 @@ namespace ams::kern {
|
|||
}
|
||||
|
||||
void KInterruptTaskManager::TaskQueue::Dequeue() {
|
||||
MESOSPHERE_ASSERT(this->head != nullptr);
|
||||
MESOSPHERE_ASSERT(this->tail != nullptr);
|
||||
|
||||
/* Pop the task from the front of the queue. */
|
||||
if (this->head == this->tail) {
|
||||
this->head = nullptr;
|
||||
this->tail = nullptr;
|
||||
|
@ -37,4 +45,51 @@ namespace ams::kern {
|
|||
}
|
||||
}
|
||||
|
||||
void KInterruptTaskManager::ThreadFunction(uintptr_t arg) {
|
||||
reinterpret_cast<KInterruptTaskManager *>(arg)->ThreadFunctionImpl();
|
||||
}
|
||||
|
||||
void KInterruptTaskManager::ThreadFunctionImpl() {
|
||||
MESOSPHERE_ASSERT_THIS();
|
||||
|
||||
while (true) {
|
||||
/* Get a task. */
|
||||
KInterruptTask *task = nullptr;
|
||||
{
|
||||
KScopedInterruptDisable di;
|
||||
|
||||
task = this->task_queue.GetHead();
|
||||
if (task == nullptr) {
|
||||
this->thread->SetState(KThread::ThreadState_Waiting);
|
||||
continue;
|
||||
}
|
||||
|
||||
this->task_queue.Dequeue();
|
||||
}
|
||||
|
||||
/* Do the task. */
|
||||
task->DoTask();
|
||||
}
|
||||
}
|
||||
|
||||
void KInterruptTaskManager::Initialize() {
|
||||
/* Reserve a thread from the system limit. */
|
||||
MESOSPHERE_ABORT_UNLESS(Kernel::GetSystemResourceLimit().Reserve(ams::svc::LimitableResource_ThreadCountMax, 1));
|
||||
|
||||
/* Create and initialize the thread. */
|
||||
this->thread = KThread::Create();
|
||||
MESOSPHERE_ABORT_UNLESS(this->thread != nullptr);
|
||||
MESOSPHERE_R_ABORT_UNLESS(KThread::InitializeHighPriorityThread(this->thread, ThreadFunction, reinterpret_cast<uintptr_t>(this)));
|
||||
KThread::Register(this->thread);
|
||||
|
||||
/* Run the thread. */
|
||||
this->thread->Run();
|
||||
}
|
||||
|
||||
void KInterruptTaskManager::EnqueueTask(KInterruptTask *task) {
|
||||
MESOSPHERE_ASSERT(!KInterruptManager::AreInterruptsEnabled());
|
||||
|
||||
MESOSPHERE_TODO_IMPLEMENT();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue