mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:57:35 +00:00
Kernel: Switch Process to InstrusiveList from InlineLinkedList
This commit is contained in:
parent
252e98761a
commit
9fccbde371
3 changed files with 37 additions and 38 deletions
|
@ -40,7 +40,7 @@ static void create_signal_trampoline();
|
||||||
|
|
||||||
RecursiveSpinLock g_processes_lock;
|
RecursiveSpinLock g_processes_lock;
|
||||||
static Atomic<pid_t> next_pid;
|
static Atomic<pid_t> next_pid;
|
||||||
READONLY_AFTER_INIT InlineLinkedList<Process>* g_processes;
|
READONLY_AFTER_INIT Process::List* g_processes;
|
||||||
READONLY_AFTER_INIT String* g_hostname;
|
READONLY_AFTER_INIT String* g_hostname;
|
||||||
READONLY_AFTER_INIT Lock* g_hostname_lock;
|
READONLY_AFTER_INIT Lock* g_hostname_lock;
|
||||||
READONLY_AFTER_INIT HashMap<String, OwnPtr<Module>>* g_modules;
|
READONLY_AFTER_INIT HashMap<String, OwnPtr<Module>>* g_modules;
|
||||||
|
@ -61,7 +61,7 @@ UNMAP_AFTER_INIT void Process::initialize()
|
||||||
g_modules = new HashMap<String, OwnPtr<Module>>;
|
g_modules = new HashMap<String, OwnPtr<Module>>;
|
||||||
|
|
||||||
next_pid.store(0, AK::MemoryOrder::memory_order_release);
|
next_pid.store(0, AK::MemoryOrder::memory_order_release);
|
||||||
g_processes = new InlineLinkedList<Process>;
|
g_processes = new Process::List();
|
||||||
g_process_groups = new ProcessGroup::List();
|
g_process_groups = new ProcessGroup::List();
|
||||||
g_hostname = new String("courage");
|
g_hostname = new String("courage");
|
||||||
g_hostname_lock = new Lock;
|
g_hostname_lock = new Lock;
|
||||||
|
@ -165,9 +165,9 @@ RefPtr<Process> Process::create_user_process(RefPtr<Thread>& first_thread, const
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
ScopedSpinLock lock(g_processes_lock);
|
|
||||||
g_processes->prepend(process);
|
|
||||||
process->ref();
|
process->ref();
|
||||||
|
ScopedSpinLock lock(g_processes_lock);
|
||||||
|
g_processes->prepend(*process);
|
||||||
}
|
}
|
||||||
error = 0;
|
error = 0;
|
||||||
return process;
|
return process;
|
||||||
|
@ -182,9 +182,9 @@ RefPtr<Process> Process::create_kernel_process(RefPtr<Thread>& first_thread, Str
|
||||||
first_thread->tss().esp = FlatPtr(entry_data); // entry function argument is expected to be in tss.esp
|
first_thread->tss().esp = FlatPtr(entry_data); // entry function argument is expected to be in tss.esp
|
||||||
|
|
||||||
if (process->pid() != 0) {
|
if (process->pid() != 0) {
|
||||||
ScopedSpinLock lock(g_processes_lock);
|
|
||||||
g_processes->prepend(process);
|
|
||||||
process->ref();
|
process->ref();
|
||||||
|
ScopedSpinLock lock(g_processes_lock);
|
||||||
|
g_processes->prepend(*process);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedSpinLock lock(g_scheduler_lock);
|
ScopedSpinLock lock(g_scheduler_lock);
|
||||||
|
@ -270,8 +270,8 @@ Process::~Process()
|
||||||
|
|
||||||
{
|
{
|
||||||
ScopedSpinLock processes_lock(g_processes_lock);
|
ScopedSpinLock processes_lock(g_processes_lock);
|
||||||
if (prev() || next())
|
if (m_list_node.is_in_list())
|
||||||
g_processes->remove(this);
|
g_processes->remove(*this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -571,17 +571,16 @@ void Process::die()
|
||||||
|
|
||||||
{
|
{
|
||||||
ScopedSpinLock lock(g_processes_lock);
|
ScopedSpinLock lock(g_processes_lock);
|
||||||
for (auto* process = g_processes->head(); process;) {
|
for (auto it = g_processes->begin(); it != g_processes->end();) {
|
||||||
auto* next_process = process->next();
|
auto& process = *it;
|
||||||
if (process->has_tracee_thread(pid())) {
|
++it;
|
||||||
dbgln_if(PROCESS_DEBUG, "Process {} ({}) is attached by {} ({}) which will exit", process->name(), process->pid(), name(), pid());
|
if (process.has_tracee_thread(pid())) {
|
||||||
process->stop_tracing();
|
dbgln_if(PROCESS_DEBUG, "Process {} ({}) is attached by {} ({}) which will exit", process.name(), process.pid(), name(), pid());
|
||||||
auto err = process->send_signal(SIGSTOP, this);
|
process.stop_tracing();
|
||||||
|
auto err = process.send_signal(SIGSTOP, this);
|
||||||
if (err.is_error())
|
if (err.is_error())
|
||||||
dbgln("Failed to send the SIGSTOP signal to {} ({})", process->name(), process->pid());
|
dbgln("Failed to send the SIGSTOP signal to {} ({})", process.name(), process.pid());
|
||||||
}
|
}
|
||||||
|
|
||||||
process = next_process;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include <AK/Checked.h>
|
#include <AK/Checked.h>
|
||||||
#include <AK/Concepts.h>
|
#include <AK/Concepts.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/InlineLinkedList.h>
|
#include <AK/IntrusiveList.h>
|
||||||
#include <AK/NonnullOwnPtrVector.h>
|
#include <AK/NonnullOwnPtrVector.h>
|
||||||
#include <AK/NonnullRefPtrVector.h>
|
#include <AK/NonnullRefPtrVector.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
|
@ -117,7 +117,6 @@ static_assert(sizeof(ProcessBase) == PAGE_SIZE);
|
||||||
class Process
|
class Process
|
||||||
: public ProcessBase
|
: public ProcessBase
|
||||||
, public RefCounted<Process>
|
, public RefCounted<Process>
|
||||||
, public InlineLinkedListNode<Process>
|
|
||||||
, public Weakable<Process> {
|
, public Weakable<Process> {
|
||||||
|
|
||||||
AK_MAKE_NONCOPYABLE(Process);
|
AK_MAKE_NONCOPYABLE(Process);
|
||||||
|
@ -125,7 +124,6 @@ class Process
|
||||||
|
|
||||||
MAKE_ALIGNED_ALLOCATED(Process, PAGE_SIZE);
|
MAKE_ALIGNED_ALLOCATED(Process, PAGE_SIZE);
|
||||||
|
|
||||||
friend class InlineLinkedListNode<Process>;
|
|
||||||
friend class Thread;
|
friend class Thread;
|
||||||
friend class CoreDump;
|
friend class CoreDump;
|
||||||
|
|
||||||
|
@ -569,8 +567,7 @@ private:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Process* m_prev { nullptr };
|
IntrusiveListNode<Process> m_list_node;
|
||||||
Process* m_next { nullptr };
|
|
||||||
|
|
||||||
String m_name;
|
String m_name;
|
||||||
|
|
||||||
|
@ -649,9 +646,12 @@ private:
|
||||||
HashMap<String, String> m_coredump_metadata;
|
HashMap<String, String> m_coredump_metadata;
|
||||||
|
|
||||||
NonnullRefPtrVector<Thread> m_threads_for_coredump;
|
NonnullRefPtrVector<Thread> m_threads_for_coredump;
|
||||||
|
|
||||||
|
public:
|
||||||
|
using List = IntrusiveList<Process, RawPtr<Process>, &Process::m_list_node>;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern InlineLinkedList<Process>* g_processes;
|
extern Process::List* g_processes;
|
||||||
extern RecursiveSpinLock g_processes_lock;
|
extern RecursiveSpinLock g_processes_lock;
|
||||||
|
|
||||||
template<IteratorFunction<Process&> Callback>
|
template<IteratorFunction<Process&> Callback>
|
||||||
|
@ -659,11 +659,11 @@ inline void Process::for_each(Callback callback)
|
||||||
{
|
{
|
||||||
VERIFY_INTERRUPTS_DISABLED();
|
VERIFY_INTERRUPTS_DISABLED();
|
||||||
ScopedSpinLock lock(g_processes_lock);
|
ScopedSpinLock lock(g_processes_lock);
|
||||||
for (auto* process = g_processes->head(); process;) {
|
for (auto it = g_processes->begin(); it != g_processes->end();) {
|
||||||
auto* next_process = process->next();
|
auto& process = *it;
|
||||||
if (callback(*process) == IterationDecision::Break)
|
++it;
|
||||||
|
if (callback(process) == IterationDecision::Break)
|
||||||
break;
|
break;
|
||||||
process = next_process;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -673,13 +673,13 @@ inline void Process::for_each_child(Callback callback)
|
||||||
VERIFY_INTERRUPTS_DISABLED();
|
VERIFY_INTERRUPTS_DISABLED();
|
||||||
ProcessID my_pid = pid();
|
ProcessID my_pid = pid();
|
||||||
ScopedSpinLock lock(g_processes_lock);
|
ScopedSpinLock lock(g_processes_lock);
|
||||||
for (auto* process = g_processes->head(); process;) {
|
for (auto it = g_processes->begin(); it != g_processes->end();) {
|
||||||
auto* next_process = process->next();
|
auto& process = *it;
|
||||||
if (process->ppid() == my_pid || process->has_tracee_thread(pid())) {
|
++it;
|
||||||
if (callback(*process) == IterationDecision::Break)
|
if (process.ppid() == my_pid || process.has_tracee_thread(pid())) {
|
||||||
|
if (callback(process) == IterationDecision::Break)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
process = next_process;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -712,13 +712,13 @@ inline void Process::for_each_in_pgrp(ProcessGroupID pgid, Callback callback)
|
||||||
{
|
{
|
||||||
VERIFY_INTERRUPTS_DISABLED();
|
VERIFY_INTERRUPTS_DISABLED();
|
||||||
ScopedSpinLock lock(g_processes_lock);
|
ScopedSpinLock lock(g_processes_lock);
|
||||||
for (auto* process = g_processes->head(); process;) {
|
for (auto it = g_processes->begin(); it != g_processes->end();) {
|
||||||
auto* next_process = process->next();
|
auto& process = *it;
|
||||||
if (!process->is_dead() && process->pgid() == pgid) {
|
++it;
|
||||||
if (callback(*process) == IterationDecision::Break)
|
if (!process.is_dead() && process.pgid() == pgid) {
|
||||||
|
if (callback(process) == IterationDecision::Break)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
process = next_process;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ KResultOr<pid_t> Process::sys$fork(RegisterState& regs)
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedSpinLock processes_lock(g_processes_lock);
|
ScopedSpinLock processes_lock(g_processes_lock);
|
||||||
g_processes->prepend(child);
|
g_processes->prepend(*child);
|
||||||
}
|
}
|
||||||
|
|
||||||
PerformanceManager::add_process_created_event(*child);
|
PerformanceManager::add_process_created_event(*child);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue