From cb5021419ea71d204effb65f604978c017dd813f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 14 Nov 2019 21:04:34 +0100 Subject: [PATCH] Kernel: Move Thread::m_joinee_exit_value into the JoinBlocker There's no need for this to be a permanent Thread member. Just use a reference in the JoinBlocker instead. --- Kernel/Process.cpp | 6 ++++-- Kernel/Scheduler.cpp | 3 ++- Kernel/Thread.cpp | 2 +- Kernel/Thread.h | 6 +++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index d1f3ab495be..f37ffdd0803 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -2906,15 +2906,17 @@ int Process::sys$join_thread(int tid, void** exit_value) // FIXME: EINVAL: 'thread' is not a joinable thread + void* joinee_exit_value = nullptr; + // FIXME: pthread_join() should not be interruptable. Enforce this somehow? - auto result = current->block(*thread); + auto result = current->block(*thread, joinee_exit_value); (void)result; // NOTE: 'thread' is very possibly deleted at this point. Clear it just to be safe. thread = nullptr; if (exit_value) - *exit_value = current->m_joinee_exit_value; + *exit_value = joinee_exit_value; return 0; } diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index b072fdfcde5..816abd5fed7 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -68,8 +68,9 @@ void Scheduler::beep() s_beep_timeout = g_uptime + 100; } -Thread::JoinBlocker::JoinBlocker(Thread& joinee) +Thread::JoinBlocker::JoinBlocker(Thread& joinee, void*& joinee_exit_value) : m_joinee(joinee) + , m_joinee_exit_value(joinee_exit_value) { ASSERT(m_joinee.m_joiner == nullptr); m_joinee.m_joiner = current; diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 208b14cec64..c99d8170522 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -240,7 +240,7 @@ void Thread::finalize() if (m_joiner) { ASSERT(m_joiner->m_joinee == this); - m_joiner->m_joinee_exit_value = m_exit_value; + static_cast(m_joiner->m_blocker)->set_joinee_exit_value(m_exit_value); m_joiner->m_joinee = nullptr; // NOTE: We clear the joiner pointer here as well, to be tidy. m_joiner = nullptr; diff --git a/Kernel/Thread.h b/Kernel/Thread.h index 0d43a197d5b..2f3d89d2a05 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -97,12 +97,14 @@ public: class JoinBlocker final : public Blocker { public: - explicit JoinBlocker(Thread& joinee); + explicit JoinBlocker(Thread& joinee, void*& joinee_exit_value); virtual bool should_unblock(Thread&, time_t now_s, long us) override; virtual const char* state_string() const override { return "Joining"; } + void set_joinee_exit_value(void* value) { m_joinee_exit_value = value; } private: Thread& m_joinee; + void*& m_joinee_exit_value; }; class FileDescriptionBlocker : public Blocker { @@ -367,10 +369,8 @@ private: SignalActionData m_signal_action_data[32]; Blocker* m_blocker { nullptr }; - // FIXME: Some of these could probably live in the JoinBlocker object instead. Thread* m_joiner { nullptr }; Thread* m_joinee { nullptr }; - void* m_joinee_exit_value { nullptr }; void* m_exit_value { nullptr }; FPUState* m_fpu_state { nullptr };