mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 02:55:49 +03:00
LibThread: Allow setting thread name in constructor
Thread now has an optional thread_name parameter to the consturctor that will call pthread_setname_np if given.
This commit is contained in:
parent
baf7e247e3
commit
0b38a553b1
Notes:
sideshowbarker
2024-07-19 10:55:37 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/0b38a553b1e Pull-request: https://github.com/SerenityOS/serenity/pull/857
@ -2,9 +2,10 @@
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
LibThread::Thread::Thread(Function<int()> action)
|
||||
LibThread::Thread::Thread(Function<int()> action, StringView thread_name)
|
||||
: CObject(nullptr)
|
||||
, m_action(move(action))
|
||||
, m_thread_name(thread_name.is_null() ? "" : thread_name)
|
||||
{
|
||||
}
|
||||
|
||||
@ -31,6 +32,10 @@ void LibThread::Thread::start()
|
||||
static_cast<void*>(this));
|
||||
|
||||
ASSERT(rc == 0);
|
||||
if (!m_thread_name.is_empty()) {
|
||||
rc = pthread_setname_np(m_tid, m_thread_name.characters(), m_thread_name.length());
|
||||
ASSERT(rc == 0);
|
||||
}
|
||||
dbg() << "Started a thread, tid = " << m_tid;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibCore/CObject.h>
|
||||
|
||||
namespace LibThread {
|
||||
@ -9,7 +10,7 @@ class Thread final : public CObject {
|
||||
C_OBJECT(Thread);
|
||||
|
||||
public:
|
||||
explicit Thread(Function<int()> action);
|
||||
explicit Thread(Function<int()> action, StringView thread_name = nullptr);
|
||||
virtual ~Thread();
|
||||
|
||||
void start();
|
||||
@ -18,6 +19,7 @@ public:
|
||||
private:
|
||||
Function<int()> m_action;
|
||||
int m_tid { -1 };
|
||||
String m_thread_name;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user