1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-02 23:22:07 +00:00

Kernel: Get rid of "main thread" concept

The idea of all processes reliably having a main thread was nice in
some ways, but cumbersome in others. More importantly, it didn't match
up with POSIX thread semantics, so let's move away from it.

This thread gets rid of Process::main_thread() and you now we just have
a bunch of Thread objects floating around each Process.

When the finalizer nukes the last Thread in a Process, it will also
tear down the Process.

There's a bunch of more things to fix around this, but this is where we
get started :^)
This commit is contained in:
Andreas Kling 2019-12-22 11:35:02 +01:00
parent 150837e7e8
commit 16812f0f98
6 changed files with 123 additions and 113 deletions

View file

@ -169,22 +169,27 @@ VFS* vfs;
// accept keyboard input.
if (text_debug) {
tty0->set_graphical(false);
auto* shell_process = Process::create_user_process("/bin/Shell", (uid_t)0, (gid_t)0, (pid_t)0, error, {}, {}, tty0);
Thread* thread = nullptr;
Process::create_user_process(thread, "/bin/Shell", (uid_t)0, (gid_t)0, (pid_t)0, error, {}, {}, tty0);
if (error != 0) {
kprintf("init_stage2: error spawning Shell: %d\n", error);
hang();
}
shell_process->main_thread().set_priority(ThreadPriority::High);
thread->set_priority(ThreadPriority::High);
} else {
tty0->set_graphical(true);
auto* system_server_process = Process::create_user_process("/bin/SystemServer", (uid_t)0, (gid_t)0, (pid_t)0, error, {}, {}, tty0);
Thread* thread = nullptr;
Process::create_user_process(thread, "/bin/SystemServer", (uid_t)0, (gid_t)0, (pid_t)0, error, {}, {}, tty0);
if (error != 0) {
kprintf("init_stage2: error spawning SystemServer: %d\n", error);
hang();
}
system_server_process->main_thread().set_priority(ThreadPriority::High);
thread->set_priority(ThreadPriority::High);
}
{
Thread* thread = nullptr;
Process::create_kernel_process(thread, "NetworkTask", NetworkTask_main);
}
Process::create_kernel_process("NetworkTask", NetworkTask_main);
current->process().sys$exit(0);
ASSERT_NOT_REACHED();
@ -308,15 +313,19 @@ extern "C" [[noreturn]] void init(u32 physical_address_for_kernel_page_tables)
Process::initialize();
Thread::initialize();
Process::create_kernel_process("init_stage2", init_stage2);
Process::create_kernel_process("syncd", [] {
Thread* init_stage2_thread = nullptr;
Process::create_kernel_process(init_stage2_thread, "init_stage2", init_stage2);
Thread* syncd_thread = nullptr;
Process::create_kernel_process(syncd_thread, "syncd", [] {
for (;;) {
VFS::the().sync();
current->sleep(1 * TICKS_PER_SECOND);
}
});
Process::create_kernel_process("Finalizer", [] {
g_finalizer = current;
Process::create_kernel_process(g_finalizer, "Finalizer", [] {
current->set_priority(ThreadPriority::Low);
for (;;) {
current->wait_on(*g_finalizer_wait_queue);