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 save_floating();
void restore_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); Scheduler::reset_task(task, image);
set_context_from_task(*task, context); task->restore_context(context);
kfree(kpathname); kfree(kpathname);

View File

@ -320,7 +320,7 @@ void Scheduler::task_yield(Context* context)
{ {
ASSERT(Interrupts::is_in_handler()); ASSERT(Interrupts::is_in_handler());
Interrupts::disable(); Interrupts::disable();
get_context_to_task(*sched_current_task, context); sched_current_task->save_context(context);
bool was_idle = false; bool was_idle = false;
if (sched_current_task->state == sched_current_task->Idle) 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 (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()) if (sched_current_task->is_user_task())
{ {
VMM::switch_to_user_address_space(sched_current_task->address_space); sched_current_task->switch_to_address_space();
VMM::apply_address_space(); sched_current_task->restore_floating();
task_restore_floating(*sched_current_task);
} }
else if (!was_idle && original_task->is_user_task() && !sched_current_task->is_user_task()) 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; sched_current_task->task_time = 20;
set_context_from_task(*sched_current_task, context); sched_current_task->restore_context(context);
return; return;
} }
} while (sched_current_task != original_task); } while (sched_current_task != original_task);
if (!was_idle && original_task->is_user_task() && original_task->state != original_task->Exited) 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 = &idle_task;
sched_current_task->task_time = frequency; 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; return;
} }

View File

@ -1,4 +1,5 @@
#include "thread/Task.h" #include "thread/Task.h"
#include "memory/VMM.h"
#include "std/string.h" #include "std/string.h"
void Task::restore_context(Context* context) void Task::restore_context(Context* context)
@ -54,3 +55,14 @@ int Task::alloc_fd_greater_than_or_equal(int base_fd)
return fd; 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;
}