summaryrefslogtreecommitdiff
path: root/Kernel/init.cpp
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-09-27 08:53:35 -0600
committerAndreas Kling <kling@serenityos.org>2020-09-27 19:46:04 +0200
commit838d9fa251ed34289cb9c77eb46f889dc9e79416 (patch)
tree0efecf56806d2fff7ebfbe5b28288a8ac01c5600 /Kernel/init.cpp
parent079486ed7eba3d15567bb5ee9677c81dd190cffa (diff)
downloadserenity-838d9fa251ed34289cb9c77eb46f889dc9e79416.zip
Kernel: Make Thread refcounted
Similar to Process, we need to make Thread refcounted. This will solve problems that will appear once we schedule threads on more than one processor. This allows us to hold onto threads without necessarily holding the scheduler lock for the entire duration.
Diffstat (limited to 'Kernel/init.cpp')
-rw-r--r--Kernel/init.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/Kernel/init.cpp b/Kernel/init.cpp
index c0d317b915..7a6751a32a 100644
--- a/Kernel/init.cpp
+++ b/Kernel/init.cpp
@@ -168,8 +168,13 @@ extern "C" [[noreturn]] void init()
Process::initialize();
Scheduler::initialize();
- Thread* init_stage2_thread = nullptr;
- Process::create_kernel_process(init_stage2_thread, "init_stage2", init_stage2);
+ {
+ RefPtr<Thread> init_stage2_thread;
+ Process::create_kernel_process(init_stage2_thread, "init_stage2", init_stage2);
+ // We need to make sure we drop the reference for init_stage2_thread
+ // before calling into Scheduler::start, otherwise we will have a
+ // dangling Thread that never gets cleaned up
+ }
Scheduler::start();
ASSERT_NOT_REACHED();
@@ -351,7 +356,7 @@ void init_stage2()
// FIXME: It would be nicer to set the mode from userspace.
tty0->set_graphical(!text_mode);
- Thread* thread = nullptr;
+ RefPtr<Thread> thread;
auto userspace_init = kernel_command_line().lookup("init").value_or("/bin/SystemServer");
Process::create_user_process(thread, userspace_init, (uid_t)0, (gid_t)0, ProcessID(0), error, {}, {}, tty0);
if (error != 0) {