Kernel: Use the new Task member functions

This commit is contained in:
apio 2022-10-17 17:07:25 +02:00
parent ce10fb5743
commit c2fa4f380d
4 changed files with 25 additions and 10 deletions

View File

@ -56,4 +56,8 @@ struct Task
void save_floating();
void restore_floating();
void switch_to_address_space();
bool has_died();
};

View File

@ -99,7 +99,7 @@ void sys_exec(Context* context, const char* pathname)
Scheduler::reset_task(task, image);
set_context_from_task(*task, context);
task->restore_context(context);
kfree(kpathname);

View File

@ -320,7 +320,7 @@ void Scheduler::task_yield(Context* context)
{
ASSERT(Interrupts::is_in_handler());
Interrupts::disable();
get_context_to_task(*sched_current_task, context);
sched_current_task->save_context(context);
bool was_idle = false;
if (sched_current_task->state == sched_current_task->Idle)
{
@ -334,15 +334,14 @@ void Scheduler::task_yield(Context* context)
{
if (sched_current_task->id != original_task->id || was_idle)
{
if (!was_idle && original_task->is_user_task() && original_task->state != original_task->Exited)
if (!was_idle && original_task->is_user_task() && !original_task->has_died())
{
task_save_floating(*original_task);
original_task->save_floating();
}
if (sched_current_task->is_user_task())
{
VMM::switch_to_user_address_space(sched_current_task->address_space);
VMM::apply_address_space();
task_restore_floating(*sched_current_task);
sched_current_task->switch_to_address_space();
sched_current_task->restore_floating();
}
else if (!was_idle && original_task->is_user_task() && !sched_current_task->is_user_task())
{
@ -351,17 +350,17 @@ void Scheduler::task_yield(Context* context)
}
}
sched_current_task->task_time = 20;
set_context_from_task(*sched_current_task, context);
sched_current_task->restore_context(context);
return;
}
} while (sched_current_task != original_task);
if (!was_idle && original_task->is_user_task() && original_task->state != original_task->Exited)
{
task_save_floating(*original_task);
original_task->save_floating();
}
sched_current_task = &idle_task;
sched_current_task->task_time = frequency;
if (!was_idle) { set_context_from_task(*sched_current_task, context); }
if (!was_idle) { sched_current_task->restore_context(context); }
return;
}

View File

@ -1,4 +1,5 @@
#include "thread/Task.h"
#include "memory/VMM.h"
#include "std/string.h"
void Task::restore_context(Context* context)
@ -53,4 +54,15 @@ int Task::alloc_fd_greater_than_or_equal(int base_fd)
if (fd == TASK_MAX_FDS) { return -1; }
return fd;
}
void Task::switch_to_address_space()
{
VMM::switch_to_user_address_space(address_space);
VMM::apply_address_space();
}
bool Task::has_died()
{
return state == Exited;
}