diff options
author | Andreas Kling <kling@serenityos.org> | 2021-08-05 22:22:26 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-06 00:37:47 +0200 |
commit | d5d8fba579666338cd928ac3ebe2270fded54287 (patch) | |
tree | b5a674049a3904b19c2e841b3179a05afbd1b204 /Kernel/Thread.h | |
parent | 07599b48decd89e868480ecad5f7dd443bfbd7d3 (diff) | |
download | serenity-d5d8fba579666338cd928ac3ebe2270fded54287.zip |
Kernel: Store Thread name as a KString
Diffstat (limited to 'Kernel/Thread.h')
-rw-r--r-- | Kernel/Thread.h | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/Kernel/Thread.h b/Kernel/Thread.h index 0bfdbf6f76..1194040e00 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -26,6 +26,7 @@ #include <Kernel/FileSystem/InodeIdentifier.h> #include <Kernel/Forward.h> #include <Kernel/KResult.h> +#include <Kernel/KString.h> #include <Kernel/LockMode.h> #include <Kernel/Scheduler.h> #include <Kernel/TimerQueue.h> @@ -178,19 +179,15 @@ public: Process& process() { return m_process; } const Process& process() const { return m_process; } - String name() const + // NOTE: This returns a null-terminated string. + StringView name() const { - // Because the name can be changed, we can't return a const - // reference here. We must make a copy - ScopedSpinLock lock(m_lock); - return m_name; + // NOTE: Whoever is calling this needs to be holding our lock while reading the name. + VERIFY(m_lock.own_lock()); + return m_name ? m_name->view() : StringView {}; } - void set_name(const StringView& s) - { - ScopedSpinLock lock(m_lock); - m_name = s; - } - void set_name(String&& name) + + void set_name(OwnPtr<KString> name) { ScopedSpinLock lock(m_lock); m_name = move(name); @@ -1218,7 +1215,7 @@ public: String backtrace(); private: - Thread(NonnullRefPtr<Process>, NonnullOwnPtr<Region>, NonnullRefPtr<Timer>, NonnullOwnPtr<FPUState>); + Thread(NonnullRefPtr<Process>, NonnullOwnPtr<Region>, NonnullRefPtr<Timer>, NonnullOwnPtr<FPUState>, OwnPtr<KString>); IntrusiveListNode<Thread> m_process_thread_list_node; int m_runnable_priority { -1 }; @@ -1349,7 +1346,7 @@ private: OwnPtr<FPUState> m_fpu_state; State m_state { Invalid }; - String m_name; + OwnPtr<KString> m_name; u32 m_priority { THREAD_PRIORITY_NORMAL }; State m_stop_state { Invalid }; |