2019-12-13 10:21:43 +01:00
|
|
|
/*
|
2021-10-04 21:59:10 +02:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2019-12-13 10:21:43 +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/>.
|
|
|
|
*/
|
|
|
|
#include <mesosphere.hpp>
|
|
|
|
|
|
|
|
namespace ams::kern {
|
|
|
|
|
2020-01-29 23:26:24 +01:00
|
|
|
void KInterruptTaskManager::TaskQueue::Enqueue(KInterruptTask *task) {
|
2020-12-18 02:18:47 +01:00
|
|
|
MESOSPHERE_ASSERT(task != m_head);
|
|
|
|
MESOSPHERE_ASSERT(task != m_tail);
|
2020-07-19 05:03:27 +02:00
|
|
|
MESOSPHERE_AUDIT(task->GetNextTask() == nullptr);
|
2020-02-10 11:26:00 +01:00
|
|
|
|
2020-01-29 23:26:24 +01:00
|
|
|
/* Insert the task into the queue. */
|
2020-12-18 02:18:47 +01:00
|
|
|
if (m_tail != nullptr) {
|
|
|
|
m_tail->SetNextTask(task);
|
2020-01-29 23:26:24 +01:00
|
|
|
} else {
|
2020-12-18 02:18:47 +01:00
|
|
|
m_head = task;
|
2020-01-29 23:26:24 +01:00
|
|
|
}
|
2019-12-13 10:21:43 +01:00
|
|
|
|
2020-12-18 02:18:47 +01:00
|
|
|
m_tail = task;
|
2020-07-19 05:03:27 +02:00
|
|
|
|
|
|
|
/* Set the next task for auditing. */
|
|
|
|
#if defined (MESOSPHERE_BUILD_FOR_AUDITING)
|
|
|
|
task->SetNextTask(GetDummyInterruptTask());
|
|
|
|
#endif
|
2019-12-13 10:21:43 +01:00
|
|
|
}
|
|
|
|
|
2020-01-29 23:26:24 +01:00
|
|
|
void KInterruptTaskManager::TaskQueue::Dequeue() {
|
2020-12-18 02:18:47 +01:00
|
|
|
MESOSPHERE_ASSERT(m_head != nullptr);
|
|
|
|
MESOSPHERE_ASSERT(m_tail != nullptr);
|
|
|
|
MESOSPHERE_AUDIT(m_tail->GetNextTask() == GetDummyInterruptTask());
|
2020-02-10 11:26:00 +01:00
|
|
|
|
|
|
|
/* Pop the task from the front of the queue. */
|
2020-12-18 02:18:47 +01:00
|
|
|
KInterruptTask *old_head = m_head;
|
2020-07-19 05:03:27 +02:00
|
|
|
|
2020-12-18 02:18:47 +01:00
|
|
|
if (m_head == m_tail) {
|
|
|
|
m_head = nullptr;
|
|
|
|
m_tail = nullptr;
|
2020-01-29 23:26:24 +01:00
|
|
|
} else {
|
2020-12-18 02:18:47 +01:00
|
|
|
m_head = m_head->GetNextTask();
|
2020-01-29 23:26:24 +01:00
|
|
|
}
|
2020-07-19 05:03:27 +02:00
|
|
|
|
|
|
|
#if defined (MESOSPHERE_BUILD_FOR_AUDITING)
|
|
|
|
old_head->SetNextTask(nullptr);
|
2020-07-28 00:22:40 +02:00
|
|
|
#else
|
|
|
|
AMS_UNUSED(old_head);
|
2020-07-19 05:03:27 +02:00
|
|
|
#endif
|
2019-12-13 10:21:43 +01:00
|
|
|
}
|
|
|
|
|
2021-09-18 01:12:01 +02:00
|
|
|
void KInterruptTaskManager::EnqueueTask(KInterruptTask *task) {
|
|
|
|
MESOSPHERE_ASSERT(!KInterruptManager::AreInterruptsEnabled());
|
|
|
|
|
|
|
|
/* Enqueue the task and signal the scheduler. */
|
|
|
|
m_task_queue.Enqueue(task);
|
|
|
|
Kernel::GetScheduler().SetInterruptTaskRunnable();
|
2020-02-10 11:26:00 +01:00
|
|
|
}
|
|
|
|
|
2021-09-18 01:12:01 +02:00
|
|
|
void KInterruptTaskManager::DoTasks() {
|
|
|
|
/* Execute pending tasks. */
|
|
|
|
const s64 start_time = KHardwareTimer::GetTick();
|
|
|
|
for (KInterruptTask *task = m_task_queue.GetHead(); task != nullptr; task = m_task_queue.GetHead()) {
|
|
|
|
/* Dequeue the task. */
|
|
|
|
m_task_queue.Dequeue();
|
2020-02-10 11:26:00 +01:00
|
|
|
|
2021-09-18 01:12:01 +02:00
|
|
|
/* Do the task with interrupts temporarily enabled. */
|
2020-02-10 11:26:00 +01:00
|
|
|
{
|
2021-09-18 01:12:01 +02:00
|
|
|
KScopedInterruptEnable ei;
|
2020-02-10 11:26:00 +01:00
|
|
|
|
2021-09-18 01:12:01 +02:00
|
|
|
task->DoTask();
|
2020-02-10 11:26:00 +01:00
|
|
|
}
|
|
|
|
}
|
2021-09-18 01:12:01 +02:00
|
|
|
const s64 end_time = KHardwareTimer::GetTick();
|
2020-02-10 11:26:00 +01:00
|
|
|
|
2021-09-18 01:12:01 +02:00
|
|
|
/* Increment the time we've spent executing. */
|
|
|
|
m_cpu_time += end_time - start_time;
|
2020-02-10 11:26:00 +01:00
|
|
|
}
|
|
|
|
|
2019-12-13 10:21:43 +01:00
|
|
|
}
|