Move the reaping logic to Scheduler

This commit is contained in:
apio 2022-12-19 12:24:15 +01:00
parent 31ee901e01
commit 92a7004c2f
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 23 additions and 6 deletions

View File

@ -1,7 +1,6 @@
#include "Log.h"
#include "arch/CPU.h"
#include "arch/MMU.h"
#include "arch/Serial.h"
#include "arch/Timer.h"
#include "boot/Init.h"
#include "boot/bootboot.h"
@ -10,6 +9,7 @@
#include "memory/KernelVM.h"
#include "memory/MemoryManager.h"
#include "thread/Scheduler.h"
#include <luna/CString.h>
#include <luna/Result.h>
#include <luna/TarStream.h>
#include <luna/Units.h>
@ -54,11 +54,7 @@ void reap_thread()
while (thread_to_reap)
{
next_thread = dying_threads.next(thread_to_reap).value_or(nullptr);
kinfoln("reap: reaping thread with id %zu", thread_to_reap->id);
auto stack = thread_to_reap->stack;
kinfoln("deleting thread stack @ %#lx, has %zu bytes of stack", stack.bottom(), stack.bytes());
MemoryManager::unmap_owned_and_free_vm(stack.bottom(), stack.bytes() / ARCH_PAGE_SIZE).release_value();
delete thread_to_reap;
Scheduler::reap_thread(thread_to_reap);
thread_to_reap = next_thread;
}
}
@ -87,8 +83,17 @@ Result<void> init()
while (TRY(stream.read_next_entry().try_set_value_with_specific_error(entry, 0)))
{
if (entry.type == TarStream::EntryType::RegularFile)
{
kinfoln("Found file %s in initial ramdisk, of size %s", entry.name,
to_dynamic_unit(entry.size).release_value().chars());
if (!strcmp(entry.name, "sys/config"))
{
auto contents = TRY(stream.read_contents_as_string(entry, 0, entry.size));
kinfoln("%s", contents.chars());
}
}
}
Thread::init();

View File

@ -95,6 +95,16 @@ namespace Scheduler
return new_kernel_thread_impl(thread);
}
void reap_thread(Thread* thread)
{
kinfoln("reap: reaping thread with id %zu", thread->id);
auto stack = thread->stack;
kinfoln("deleting thread stack @ %#lx, has %zu bytes of stack", stack.bottom(), stack.bytes());
// FIXME: Propagate errors I guess?
MemoryManager::unmap_owned_and_free_vm(stack.bottom(), stack.bytes() / ARCH_PAGE_SIZE).release_value();
delete thread;
}
Thread* pick_task()
{
Thread* old = g_current;

View File

@ -14,6 +14,8 @@ namespace Scheduler
Thread* pick_task();
void reap_thread(Thread* thread);
void switch_task(Registers* regs);
void invoke(Registers* regs);