1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:57:43 +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

@ -37,8 +37,8 @@ class Process : public InlineLinkedListNode<Process>
friend class Thread;
public:
static Process* create_kernel_process(String&& name, void (*entry)());
static Process* create_user_process(const String& path, uid_t, gid_t, pid_t ppid, int& error, Vector<String>&& arguments = Vector<String>(), Vector<String>&& environment = Vector<String>(), TTY* = nullptr);
static Process* create_kernel_process(Thread*& first_thread, String&& name, void (*entry)());
static Process* create_user_process(Thread*& first_thread, const String& path, uid_t, gid_t, pid_t ppid, int& error, Vector<String>&& arguments = Vector<String>(), Vector<String>&& environment = Vector<String>(), TTY* = nullptr);
~Process();
static Vector<pid_t> all_pids();
@ -56,9 +56,6 @@ public:
bool is_dead() const { return m_dead; }
Thread& main_thread() { return *m_main_thread; }
const Thread& main_thread() const { return *m_main_thread; }
bool is_ring0() const { return m_ring == Ring0; }
bool is_ring3() const { return m_ring == Ring3; }
@ -297,7 +294,9 @@ public:
void terminate_due_to_signal(u8 signal);
void send_signal(u8, Process* sender);
int thread_count() const;
u16 thread_count() const { return m_thread_count; }
Thread& any_thread();
Lock& big_lock() { return m_big_lock; }
@ -310,7 +309,7 @@ private:
friend class Scheduler;
friend class Region;
Process(const String& name, uid_t, gid_t, pid_t ppid, RingLevel, RefPtr<Custody> cwd = nullptr, RefPtr<Custody> executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr);
Process(Thread*& first_thread, const String& name, uid_t, gid_t, pid_t ppid, RingLevel, RefPtr<Custody> cwd = nullptr, RefPtr<Custody> executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr);
Range allocate_range(VirtualAddress, size_t);
@ -325,8 +324,6 @@ private:
KResult do_kill(Process&, int signal);
KResult do_killpg(pid_t pgrp, int signal);
Thread* m_main_thread { nullptr };
RefPtr<PageDirectory> m_page_directory;
Process* m_prev { nullptr };
@ -356,6 +353,7 @@ private:
RingLevel m_ring { Ring0 };
u8 m_termination_status { 0 };
u8 m_termination_signal { 0 };
u16 m_thread_count { 0 };
bool m_being_inspected { false };
bool m_dead { false };
@ -465,8 +463,8 @@ inline void Process::for_each_thread(Callback callback) const
pid_t my_pid = pid();
if (my_pid == 0) {
// NOTE: Special case the colonel thread, since its main thread is not in the global thread table.
callback(const_cast<Thread&>(main_thread()));
// NOTE: Special case the colonel process, since its main thread is not in the global thread table.
callback(*g_colonel);
return;
}