diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-12-29 00:46:21 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-12-29 12:04:15 +0100 |
commit | d7ec5d042f60ce2a31569a75383eaa4551f86217 (patch) | |
tree | 8a796cd63e40b04344c030a6cd0fc918eebb53af /Kernel/Process.cpp | |
parent | 3d0b5efcfc06f1aa977fbc1eb074fb54c36e2869 (diff) | |
download | serenity-d7ec5d042f60ce2a31569a75383eaa4551f86217.zip |
Kernel: Port Process to ListedRefCounted
Diffstat (limited to 'Kernel/Process.cpp')
-rw-r--r-- | Kernel/Process.cpp | 32 |
1 files changed, 6 insertions, 26 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 3fa3e4d734..96d07ee458 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -43,7 +43,7 @@ static void create_signal_trampoline(); RecursiveSpinlock g_profiling_lock; static Atomic<pid_t> next_pid; -static Singleton<SpinlockProtected<Process::List>> s_processes; +static Singleton<SpinlockProtected<Process::List>> s_all_instances; READONLY_AFTER_INIT Memory::Region* g_signal_trampoline_region; static Singleton<MutexProtected<String>> s_hostname; @@ -53,9 +53,9 @@ MutexProtected<String>& hostname() return *s_hostname; } -SpinlockProtected<Process::List>& processes() +SpinlockProtected<Process::List>& Process::all_instances() { - return *s_processes; + return *s_all_instances; } ProcessID Process::allocate_pid() @@ -123,7 +123,7 @@ void Process::register_new(Process& process) { // Note: this is essentially the same like process->ref() RefPtr<Process> new_process = process; - processes().with([&](auto& list) { + all_instances().with([&](auto& list) { list.prepend(process); }); } @@ -268,26 +268,6 @@ Process::~Process() PerformanceManager::add_process_exit_event(*this); } -bool Process::unref() const -{ - // NOTE: We need to obtain the process list lock before doing anything, - // because otherwise someone might get in between us lowering the - // refcount and acquiring the lock. - auto did_hit_zero = processes().with([&](auto& list) { - auto new_ref_count = deref_base(); - if (new_ref_count > 0) - return false; - - if (m_list_node.is_in_list()) - list.remove(*const_cast<Process*>(this)); - return true; - }); - - if (did_hit_zero) - delete this; - return did_hit_zero; -} - // Make sure the compiler doesn't "optimize away" this function: extern void signal_trampoline_dummy() __attribute__((used)); void signal_trampoline_dummy() @@ -390,7 +370,7 @@ void Process::crash(int signal, FlatPtr ip, bool out_of_memory) RefPtr<Process> Process::from_pid(ProcessID pid) { - return processes().with([&](const auto& list) -> RefPtr<Process> { + return all_instances().with([&](const auto& list) -> RefPtr<Process> { for (auto const& process : list) { if (process.pid() == pid) return &process; @@ -690,7 +670,7 @@ void Process::die() m_threads_for_coredump.append(thread); }); - processes().with([&](const auto& list) { + all_instances().with([&](const auto& list) { for (auto it = list.begin(); it != list.end();) { auto& process = *it; ++it; |