1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 14:07:42 +00:00

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.
This commit is contained in:
Andreas Kling 2019-11-14 21:04:34 +01:00
parent 69efa3f630
commit cb5021419e
4 changed files with 10 additions and 7 deletions

View file

@ -2906,15 +2906,17 @@ int Process::sys$join_thread(int tid, void** exit_value)
// FIXME: EINVAL: 'thread' is not a joinable thread // FIXME: EINVAL: 'thread' is not a joinable thread
void* joinee_exit_value = nullptr;
// FIXME: pthread_join() should not be interruptable. Enforce this somehow? // FIXME: pthread_join() should not be interruptable. Enforce this somehow?
auto result = current->block<Thread::JoinBlocker>(*thread); auto result = current->block<Thread::JoinBlocker>(*thread, joinee_exit_value);
(void)result; (void)result;
// NOTE: 'thread' is very possibly deleted at this point. Clear it just to be safe. // NOTE: 'thread' is very possibly deleted at this point. Clear it just to be safe.
thread = nullptr; thread = nullptr;
if (exit_value) if (exit_value)
*exit_value = current->m_joinee_exit_value; *exit_value = joinee_exit_value;
return 0; return 0;
} }

View file

@ -68,8 +68,9 @@ void Scheduler::beep()
s_beep_timeout = g_uptime + 100; 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(joinee)
, m_joinee_exit_value(joinee_exit_value)
{ {
ASSERT(m_joinee.m_joiner == nullptr); ASSERT(m_joinee.m_joiner == nullptr);
m_joinee.m_joiner = current; m_joinee.m_joiner = current;

View file

@ -240,7 +240,7 @@ void Thread::finalize()
if (m_joiner) { if (m_joiner) {
ASSERT(m_joiner->m_joinee == this); ASSERT(m_joiner->m_joinee == this);
m_joiner->m_joinee_exit_value = m_exit_value; static_cast<JoinBlocker*>(m_joiner->m_blocker)->set_joinee_exit_value(m_exit_value);
m_joiner->m_joinee = nullptr; m_joiner->m_joinee = nullptr;
// NOTE: We clear the joiner pointer here as well, to be tidy. // NOTE: We clear the joiner pointer here as well, to be tidy.
m_joiner = nullptr; m_joiner = nullptr;

View file

@ -97,12 +97,14 @@ public:
class JoinBlocker final : public Blocker { class JoinBlocker final : public Blocker {
public: 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 bool should_unblock(Thread&, time_t now_s, long us) override;
virtual const char* state_string() const override { return "Joining"; } virtual const char* state_string() const override { return "Joining"; }
void set_joinee_exit_value(void* value) { m_joinee_exit_value = value; }
private: private:
Thread& m_joinee; Thread& m_joinee;
void*& m_joinee_exit_value;
}; };
class FileDescriptionBlocker : public Blocker { class FileDescriptionBlocker : public Blocker {
@ -367,10 +369,8 @@ private:
SignalActionData m_signal_action_data[32]; SignalActionData m_signal_action_data[32];
Blocker* m_blocker { nullptr }; Blocker* m_blocker { nullptr };
// FIXME: Some of these could probably live in the JoinBlocker object instead.
Thread* m_joiner { nullptr }; Thread* m_joiner { nullptr };
Thread* m_joinee { nullptr }; Thread* m_joinee { nullptr };
void* m_joinee_exit_value { nullptr };
void* m_exit_value { nullptr }; void* m_exit_value { nullptr };
FPUState* m_fpu_state { nullptr }; FPUState* m_fpu_state { nullptr };