Scheduler: Implement a find_by_pid function
This commit is contained in:
parent
8b17065718
commit
4f41b9ed37
@ -29,4 +29,6 @@ namespace Scheduler
|
||||
void reset_task(Task* task, ELFImage* new_image);
|
||||
|
||||
void append_task(Task* task);
|
||||
|
||||
Task* find_by_pid(uint64_t pid);
|
||||
}
|
@ -33,6 +33,31 @@ extern "C" void idle_task_function();
|
||||
|
||||
static uint64_t frequency;
|
||||
|
||||
template <typename Callback> void sched_for_each_task(Callback callback)
|
||||
{
|
||||
Task* task = base_task;
|
||||
if (!task) return;
|
||||
do {
|
||||
bool will_continue = callback(task);
|
||||
if (!will_continue) break;
|
||||
task = task->next_task;
|
||||
} while (task != base_task);
|
||||
}
|
||||
|
||||
Task* Scheduler::find_by_pid(uint64_t pid)
|
||||
{
|
||||
Task* result = nullptr;
|
||||
sched_for_each_task([&](Task* task) {
|
||||
if (task->id == pid)
|
||||
{
|
||||
result = task;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
void Scheduler::append_task(Task* task)
|
||||
{
|
||||
if (!base_task)
|
||||
@ -295,17 +320,15 @@ void Scheduler::reap_tasks()
|
||||
|
||||
static void sched_decrement_sleep_times()
|
||||
{
|
||||
Task* task = base_task;
|
||||
if (!task) return;
|
||||
do {
|
||||
sched_for_each_task([](Task* task) {
|
||||
if (task->task_sleep > 0)
|
||||
{
|
||||
task->task_sleep -= frequency;
|
||||
if (task->task_sleep < 0) task->task_sleep = 0;
|
||||
}
|
||||
if (task->task_sleep == 0 && task->state == task->Sleeping) task->state = task->Running;
|
||||
task = task->next_task;
|
||||
} while (task != base_task);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void Scheduler::task_tick(Context* context)
|
||||
|
Loading…
Reference in New Issue
Block a user