Compare commits
No commits in common. "5b72144fac518345331380684f9380a007078f4b" and "60520dff4cb55568f392bd2da519d0e14fcbab93" have entirely different histories.
5b72144fac
...
60520dff4c
@ -1,6 +1,7 @@
|
||||
#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"
|
||||
@ -9,7 +10,6 @@
|
||||
#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>
|
||||
@ -46,7 +46,22 @@ void reap_thread()
|
||||
auto dying_threads = Scheduler::check_for_dying_threads();
|
||||
CPU::enable_interrupts();
|
||||
|
||||
dying_threads.consume([](Thread* thread) { Scheduler::reap_thread(thread); });
|
||||
if (dying_threads.count())
|
||||
{
|
||||
Thread* thread_to_reap = dying_threads.expect_first();
|
||||
Thread* next_thread = thread_to_reap;
|
||||
|
||||
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;
|
||||
thread_to_reap = next_thread;
|
||||
}
|
||||
}
|
||||
|
||||
kernel_sleep(250);
|
||||
}
|
||||
@ -72,17 +87,8 @@ 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();
|
||||
|
@ -95,16 +95,6 @@ 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;
|
||||
|
@ -14,8 +14,6 @@ namespace Scheduler
|
||||
|
||||
Thread* pick_task();
|
||||
|
||||
void reap_thread(Thread* thread);
|
||||
|
||||
void switch_task(Registers* regs);
|
||||
|
||||
void invoke(Registers* regs);
|
||||
|
@ -8,7 +8,6 @@ extern "C"
|
||||
int memcmp(const void* a, const void* b, usize n);
|
||||
void* memmove(void* dest, const void* src, usize n);
|
||||
usize strlen(const char* str);
|
||||
int strcmp(const char* a, const char* b);
|
||||
|
||||
usize wcslen(const wchar_t* str);
|
||||
|
||||
|
@ -155,45 +155,26 @@ template <typename T> class DoublyLinkedList
|
||||
return nonnull_or_error((T*)extract_node(item)->get_last());
|
||||
}
|
||||
|
||||
// Iterates over the elements of the DoublyLinkedList from start to end, calling callback for every element.
|
||||
template <typename Callback> void for_each(Callback callback)
|
||||
{
|
||||
for (Node* node = m_start_node; node; node = node->get_next()) { callback((T*)node); }
|
||||
}
|
||||
|
||||
// Iterates over the elements of the DoublyLinkedList from end to start, calling callback for every element.
|
||||
template <typename Callback> void for_each_reversed(Callback callback)
|
||||
{
|
||||
for (Node* node = m_end_node; node; node = node->get_last()) { callback((T*)node); }
|
||||
}
|
||||
|
||||
// Iterates over the elements of the DoublyLinkedList from the element after 'start' to end, calling callback for
|
||||
// every element.
|
||||
template <typename Callback> void for_each_after(T* start, Callback callback)
|
||||
{
|
||||
for (Node* node = extract_node(start)->m_next_node; node; node = node->get_next()) { callback((T*)node); }
|
||||
}
|
||||
|
||||
// Iterates over the elements of the DoublyLinkedList from the element before 'end' to start, calling callback for
|
||||
// every element.
|
||||
template <typename Callback> void for_each_before(T* end, Callback callback)
|
||||
{
|
||||
for (Node* node = extract_node(end)->m_last_node; node; node = node->get_last()) { callback((T*)node); }
|
||||
}
|
||||
|
||||
// Iterates over the elements of the DoublyLinkedList from start to end, removing each element before passing it to
|
||||
// the callback.
|
||||
template <typename Callback> void consume(Callback callback)
|
||||
{
|
||||
for (Node* node = m_start_node; node;)
|
||||
{
|
||||
T* current = (T*)node;
|
||||
node = node->get_next();
|
||||
remove(current);
|
||||
callback(current);
|
||||
}
|
||||
}
|
||||
|
||||
usize count()
|
||||
{
|
||||
return m_count;
|
||||
|
@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include <luna/OwnedStringView.h>
|
||||
#include <luna/Result.h>
|
||||
#include <luna/Types.h>
|
||||
|
||||
@ -34,8 +33,6 @@ class TarStream
|
||||
|
||||
usize read_contents(const Entry& entry, char* buf, usize offset, usize length);
|
||||
|
||||
Result<OwnedStringView> read_contents_as_string(const Entry& entry, usize offset, usize max);
|
||||
|
||||
private:
|
||||
struct [[gnu::packed]] TarHeader
|
||||
{
|
||||
|
@ -46,16 +46,6 @@ extern "C"
|
||||
return (usize)(i - str);
|
||||
}
|
||||
|
||||
int strcmp(const char* a, const char* b)
|
||||
{
|
||||
while (*a && (*a == *b))
|
||||
{
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
return *(const u8*)a - *(const u8*)b;
|
||||
}
|
||||
|
||||
usize wcslen(const wchar_t* str)
|
||||
{
|
||||
const wchar_t* i = str;
|
||||
|
@ -1,6 +1,5 @@
|
||||
#define _LUNA_SYSTEM_ERROR_EXTENSIONS
|
||||
#include <luna/Alignment.h>
|
||||
#include <luna/Alloc.h>
|
||||
#include <luna/CString.h>
|
||||
#include <luna/NumberParsing.h>
|
||||
#include <luna/TarStream.h>
|
||||
@ -95,15 +94,4 @@ usize TarStream::read_contents(const Entry& entry, char* buf, usize offset, usiz
|
||||
memcpy(buf, offset_ptr(m_base, entry.pos + offset), length);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
Result<OwnedStringView> TarStream::read_contents_as_string(const Entry& entry, usize offset, usize max)
|
||||
{
|
||||
char* buf = TRY(make_array<char>(max + 1));
|
||||
|
||||
usize nread = read_contents(entry, buf, offset, max);
|
||||
|
||||
buf[nread] = 0;
|
||||
|
||||
return OwnedStringView{buf};
|
||||
}
|
Loading…
Reference in New Issue
Block a user