1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 18:57:34 +00:00

Kernel: Make Threads always have a name

We previously allowed Thread to exist in a state where its m_name was
null, and had to work around that in various places.

This patch removes that possibility and forces those who would create a
thread (or change the name of one) to provide a NonnullOwnPtr<KString>
with the name.
This commit is contained in:
Andreas Kling 2021-09-06 12:44:27 +02:00
parent cda2b9e71c
commit 7981422500
7 changed files with 25 additions and 13 deletions

View file

@ -43,11 +43,16 @@ KResultOr<FlatPtr> Process::sys$create_thread(void* (*entry)(void*), Userspace<c
auto thread = TRY(Thread::try_create(*this));
// FIXME: Don't make a temporary String here
auto new_thread_name = KString::try_create(String::formatted("{} [{}]", m_name, thread->tid().value()));
if (!new_thread_name)
return ENOMEM;
// We know this thread is not the main_thread,
// So give it a unique name until the user calls $set_thread_name on it
// length + 4 to give space for our extra junk at the end
StringBuilder builder(m_name.length() + 4);
thread->set_name(KString::try_create(String::formatted("{} [{}]", m_name, thread->tid().value())));
thread->set_name(new_thread_name.release_nonnull());
if (!is_thread_joinable)
thread->detach();