Compare commits
No commits in common. "6cd25fb9b1a65760f1e8af7c1d6589138f2e8029" and "48fe2d4b04b06d3c734ab9112fbfa97c9aff9dc3" have entirely different histories.
6cd25fb9b1
...
48fe2d4b04
@ -43,7 +43,7 @@ void Thread::set_arguments(u64 arg1, u64 arg2, u64 arg3, u64 arg4)
|
||||
|
||||
void switch_context(Thread* old_thread, Thread* new_thread, Registers* regs)
|
||||
{
|
||||
if (!old_thread->is_idle()) memcpy(&old_thread->regs, regs, sizeof(Registers));
|
||||
if (!old_thread->is_idle) memcpy(&old_thread->regs, regs, sizeof(Registers));
|
||||
|
||||
memcpy(regs, &new_thread->regs, sizeof(Registers));
|
||||
}
|
@ -18,7 +18,7 @@ namespace Scheduler
|
||||
g_idle.id = 0;
|
||||
g_idle.init_regs_kernel();
|
||||
g_idle.set_ip((u64)CPU::idle_loop);
|
||||
g_idle.state = ThreadState::Idle;
|
||||
g_idle.is_idle = true;
|
||||
|
||||
g_idle.ticks_left = 1;
|
||||
|
||||
@ -86,31 +86,24 @@ namespace Scheduler
|
||||
Thread* pick_task()
|
||||
{
|
||||
Thread* old = g_current;
|
||||
if (old->is_idle())
|
||||
if (old->is_idle)
|
||||
{
|
||||
auto maybe_last = g_threads.last();
|
||||
if (maybe_last.has_error()) // No threads!!
|
||||
auto maybe_first = g_threads.last();
|
||||
if (maybe_first.has_error()) // No threads!!
|
||||
return &g_idle;
|
||||
g_current = old = maybe_last.value();
|
||||
g_current = old = maybe_first.value();
|
||||
}
|
||||
|
||||
bool has_found_thread = false;
|
||||
|
||||
do {
|
||||
auto maybe_next = g_threads.next(g_current);
|
||||
if (maybe_next.has_error()) g_current = g_threads.first().value();
|
||||
else
|
||||
g_current = maybe_next.value();
|
||||
|
||||
if (g_current->state == ThreadState::Runnable)
|
||||
{
|
||||
has_found_thread = true;
|
||||
if (true) // FIXME: Check if the current task is runnable.
|
||||
break;
|
||||
}
|
||||
} while (g_current != old);
|
||||
|
||||
if (!has_found_thread) g_current = &g_idle;
|
||||
|
||||
return g_current;
|
||||
}
|
||||
|
||||
@ -118,7 +111,7 @@ namespace Scheduler
|
||||
{
|
||||
if (old_thread != new_thread) switch_context(old_thread, new_thread, regs);
|
||||
|
||||
if (new_thread->is_idle())
|
||||
if (new_thread->is_idle)
|
||||
{
|
||||
new_thread->ticks_left = 1; // The idle task only runs for 1 tick so we can check for new runnable tasks
|
||||
// as fast as possible.
|
||||
|
@ -10,13 +10,6 @@
|
||||
#error "Unknown architecture."
|
||||
#endif
|
||||
|
||||
enum class ThreadState
|
||||
{
|
||||
Idle,
|
||||
Runnable,
|
||||
Sleeping
|
||||
};
|
||||
|
||||
struct Thread : public DoublyLinkedListNode<Thread>
|
||||
{
|
||||
Registers regs;
|
||||
@ -29,12 +22,7 @@ struct Thread : public DoublyLinkedListNode<Thread>
|
||||
|
||||
u64 ticks_left;
|
||||
|
||||
ThreadState state = ThreadState::Runnable;
|
||||
|
||||
bool is_idle()
|
||||
{
|
||||
return state == ThreadState::Idle;
|
||||
}
|
||||
bool is_idle = false;
|
||||
|
||||
void init_regs_kernel();
|
||||
void init_regs_user();
|
||||
|
Loading…
x
Reference in New Issue
Block a user