Add a basic scheduler with threads #18

Merged
apio merged 19 commits from threads into restart 2022-12-07 16:11:59 +00:00
Showing only changes of commit 6cd25fb9b1 - Show all commits

View File

@ -88,22 +88,29 @@ namespace Scheduler
Thread* old = g_current;
if (old->is_idle())
{
auto maybe_first = g_threads.last();
if (maybe_first.has_error()) // No threads!!
auto maybe_last = g_threads.last();
if (maybe_last.has_error()) // No threads!!
return &g_idle;
g_current = old = maybe_first.value();
g_current = old = maybe_last.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 (true) // FIXME: Check if the current task is runnable.
if (g_current->state == ThreadState::Runnable)
{
has_found_thread = true;
break;
}
} while (g_current != old);
if (!has_found_thread) g_current = &g_idle;
return g_current;
}