diff options
author | Tom <tomut@yahoo.com> | 2020-09-27 08:53:35 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-27 19:46:04 +0200 |
commit | 838d9fa251ed34289cb9c77eb46f889dc9e79416 (patch) | |
tree | 0efecf56806d2fff7ebfbe5b28288a8ac01c5600 /Kernel/Syscalls/fork.cpp | |
parent | 079486ed7eba3d15567bb5ee9677c81dd190cffa (diff) | |
download | serenity-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/Syscalls/fork.cpp')
-rw-r--r-- | Kernel/Syscalls/fork.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Kernel/Syscalls/fork.cpp b/Kernel/Syscalls/fork.cpp index d6ca53daf4..c488391179 100644 --- a/Kernel/Syscalls/fork.cpp +++ b/Kernel/Syscalls/fork.cpp @@ -36,8 +36,10 @@ namespace Kernel { pid_t Process::sys$fork(RegisterState& regs) { REQUIRE_PROMISE(proc); - Thread* child_first_thread = nullptr; - auto* child = new Process(child_first_thread, m_name, m_uid, m_gid, m_pid, m_is_kernel_process, m_cwd, m_executable, m_tty, this); + RefPtr<Thread> child_first_thread; + auto child = adopt(*new Process(child_first_thread, m_name, m_uid, m_gid, m_pid, m_is_kernel_process, m_cwd, m_executable, m_tty, this)); + if (!child_first_thread) + return -ENOMEM; child->m_root_directory = m_root_directory; child->m_root_directory_relative_to_global_root = m_root_directory_relative_to_global_root; child->m_promises = m_promises; @@ -92,6 +94,7 @@ pid_t Process::sys$fork(RegisterState& regs) { ScopedSpinLock lock(g_processes_lock); g_processes->prepend(child); + child->ref(); // This reference will be dropped by Process::reap } child_first_thread->set_affinity(Thread::current()->affinity()); |