diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2023-02-04 14:11:35 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-02-06 20:36:53 +0100 |
commit | 1014aefe649aa50d69aa10aba647872e2ff99a93 (patch) | |
tree | 323d31d45de5bda44dad6cc5e3215ba910467877 /Kernel/Thread.h | |
parent | fe7b08dad7a41251469840ab15ab90bc9b31caa8 (diff) | |
download | serenity-1014aefe649aa50d69aa10aba647872e2ff99a93.zip |
Kernel: Protect Thread::m_name with a spinlock
This replaces manually grabbing the thread's main lock.
This lets us remove the `get_thread_name` and `set_thread_name` syscalls
from the big lock. :^)
Diffstat (limited to 'Kernel/Thread.h')
-rw-r--r-- | Kernel/Thread.h | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/Kernel/Thread.h b/Kernel/Thread.h index a45889c2ea..7e7e8559e3 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -94,19 +94,11 @@ public: Process& process() { return m_process; } Process const& process() const { return m_process; } - // NOTE: This returns a null-terminated string. - StringView name() const + SpinlockProtected<NonnullOwnPtr<KString>, LockRank::None> const& name() const { - // NOTE: Whoever is calling this needs to be holding our lock while reading the name. - VERIFY(m_lock.is_locked_by_current_processor()); - return m_name->view(); - } - - void set_name(NonnullOwnPtr<KString> name) - { - SpinlockLocker lock(m_lock); - m_name = move(name); + return m_name; } + void set_name(NonnullOwnPtr<KString> name); void finalize(); @@ -1229,7 +1221,7 @@ private: FPUState m_fpu_state {}; State m_state { Thread::State::Invalid }; - NonnullOwnPtr<KString> m_name; + SpinlockProtected<NonnullOwnPtr<KString>, LockRank::None> m_name; u32 m_priority { THREAD_PRIORITY_NORMAL }; State m_stop_state { Thread::State::Invalid }; |