forked from Bananymous/banan-os
Kernel: More rework on Scheduler
This commit is contained in:
parent
e7a577f54a
commit
1dabe7a222
|
@ -28,18 +28,21 @@ namespace Kernel
|
|||
|
||||
void wake_threads();
|
||||
[[nodiscard]] bool save_current_thread();
|
||||
void get_next_thread();
|
||||
void remove_and_advance_current_thread();
|
||||
void advance_current_thread();
|
||||
[[noreturn]] void execute_current_thread();
|
||||
|
||||
private:
|
||||
struct ActiveThread
|
||||
{
|
||||
ActiveThread(const BAN::RefPtr<Thread>& thread) : thread(thread) {}
|
||||
BAN::RefPtr<Thread> thread;
|
||||
uint64_t padding = 0;
|
||||
};
|
||||
|
||||
struct SleepingThread
|
||||
{
|
||||
SleepingThread(const BAN::RefPtr<Thread>& thread, uint64_t wake_time) : thread(thread), wake_time(wake_time) {}
|
||||
BAN::RefPtr<Thread> thread;
|
||||
uint64_t wake_time;
|
||||
};
|
||||
|
|
|
@ -53,6 +53,7 @@ namespace Kernel
|
|||
|
||||
void Scheduler::reschedule()
|
||||
{
|
||||
VERIFY_CLI();
|
||||
ASSERT(InterruptController::get().is_in_service(PIT_IRQ));
|
||||
InterruptController::get().eoi(PIT_IRQ);
|
||||
|
||||
|
@ -81,23 +82,17 @@ namespace Kernel
|
|||
|
||||
// This should work as we released enough memory from sleeping thread
|
||||
static_assert(sizeof(ActiveThread) == sizeof(SleepingThread));
|
||||
MUST(m_active_threads.push_back({ thread, 0 }));
|
||||
MUST(m_active_threads.emplace_back(thread));
|
||||
thread.clear();
|
||||
}
|
||||
}
|
||||
|
||||
BAN::ErrorOr<void> Scheduler::add_thread(BAN::RefCounted<Thread> thread)
|
||||
BAN::ErrorOr<void> Scheduler::add_thread(BAN::RefPtr<Thread> thread)
|
||||
{
|
||||
if (interrupts_disabled())
|
||||
{
|
||||
TRY(m_active_threads.push_back({ thread, 0 }));
|
||||
}
|
||||
else
|
||||
{
|
||||
DISABLE_INTERRUPTS();
|
||||
TRY(m_active_threads.push_back({ thread, 0 }));
|
||||
ENABLE_INTERRUPTS();
|
||||
}
|
||||
return {};
|
||||
auto flags = disable_interrupts_and_get_flags();
|
||||
BAN::ErrorOr<void> result = m_active_threads.emplace_back(thread);
|
||||
restore_flags(flags);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Scheduler::advance_current_thread()
|
||||
|
@ -176,6 +171,7 @@ namespace Kernel
|
|||
#pragma GCC optimize("O0")
|
||||
void Scheduler::set_current_thread_sleeping(uint64_t wake_time)
|
||||
{
|
||||
VERIFY_STI();
|
||||
DISABLE_INTERRUPTS();
|
||||
|
||||
ASSERT(m_current_thread);
|
||||
|
@ -183,7 +179,10 @@ namespace Kernel
|
|||
auto sleeping = m_current_thread->thread;
|
||||
|
||||
if (save_current_thread())
|
||||
{
|
||||
ENABLE_INTERRUPTS();
|
||||
return;
|
||||
}
|
||||
remove_and_advance_current_thread();
|
||||
|
||||
auto it = m_sleeping_threads.begin();
|
||||
|
@ -203,6 +202,7 @@ namespace Kernel
|
|||
|
||||
void Scheduler::set_current_thread_done()
|
||||
{
|
||||
VERIFY_STI();
|
||||
DISABLE_INTERRUPTS();
|
||||
|
||||
ASSERT(m_current_thread);
|
||||
|
|
Loading…
Reference in New Issue