mirror of
https://github.com/RGBCube/serenity
synced 2025-07-02 23:42:13 +00:00
LibThreading: Use Threading namespace in Thread.cpp
This commit is contained in:
parent
bfb3fc58dd
commit
7fd7562140
1 changed files with 10 additions and 6 deletions
|
@ -9,7 +9,9 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
Threading::Thread::Thread(Function<intptr_t()> action, StringView thread_name)
|
namespace Threading {
|
||||||
|
|
||||||
|
Thread::Thread(Function<intptr_t()> action, StringView thread_name)
|
||||||
: Core::Object(nullptr)
|
: Core::Object(nullptr)
|
||||||
, m_action(move(action))
|
, m_action(move(action))
|
||||||
, m_thread_name(thread_name.is_null() ? ""sv : thread_name)
|
, m_thread_name(thread_name.is_null() ? ""sv : thread_name)
|
||||||
|
@ -21,7 +23,7 @@ Threading::Thread::Thread(Function<intptr_t()> action, StringView thread_name)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Threading::Thread::~Thread()
|
Thread::~Thread()
|
||||||
{
|
{
|
||||||
if (m_tid && !m_detached) {
|
if (m_tid && !m_detached) {
|
||||||
dbgln("Destroying thread \"{}\"({}) while it is still running!", m_thread_name, m_tid);
|
dbgln("Destroying thread \"{}\"({}) while it is still running!", m_thread_name, m_tid);
|
||||||
|
@ -29,7 +31,7 @@ Threading::Thread::~Thread()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> Threading::Thread::set_priority(int priority)
|
ErrorOr<void> Thread::set_priority(int priority)
|
||||||
{
|
{
|
||||||
// MacOS has an extra __opaque field, so list initialization will not compile on MacOS Lagom.
|
// MacOS has an extra __opaque field, so list initialization will not compile on MacOS Lagom.
|
||||||
sched_param scheduling_parameters {};
|
sched_param scheduling_parameters {};
|
||||||
|
@ -40,7 +42,7 @@ ErrorOr<void> Threading::Thread::set_priority(int priority)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<int> Threading::Thread::get_priority() const
|
ErrorOr<int> Thread::get_priority() const
|
||||||
{
|
{
|
||||||
sched_param scheduling_parameters {};
|
sched_param scheduling_parameters {};
|
||||||
int policy;
|
int policy;
|
||||||
|
@ -50,7 +52,7 @@ ErrorOr<int> Threading::Thread::get_priority() const
|
||||||
return scheduling_parameters.sched_priority;
|
return scheduling_parameters.sched_priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Threading::Thread::start()
|
void Thread::start()
|
||||||
{
|
{
|
||||||
int rc = pthread_create(
|
int rc = pthread_create(
|
||||||
&m_tid,
|
&m_tid,
|
||||||
|
@ -74,7 +76,7 @@ void Threading::Thread::start()
|
||||||
m_started = true;
|
m_started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Threading::Thread::detach()
|
void Thread::detach()
|
||||||
{
|
{
|
||||||
VERIFY(!m_detached);
|
VERIFY(!m_detached);
|
||||||
|
|
||||||
|
@ -83,3 +85,5 @@ void Threading::Thread::detach()
|
||||||
|
|
||||||
m_detached = true;
|
m_detached = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue