mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:14:58 +00:00
LibThreading: Add thread priority controls to Thread
This exposes the now properly working pthread APIs on the higher level.
This commit is contained in:
parent
e63f3f3c96
commit
7237be763f
2 changed files with 24 additions and 0 deletions
|
@ -29,6 +29,27 @@ Threading::Thread::~Thread()
|
|||
}
|
||||
}
|
||||
|
||||
ErrorOr<void> Threading::Thread::set_priority(int priority)
|
||||
{
|
||||
// MacOS has an extra __opaque field, so list initialization will not compile on MacOS Lagom.
|
||||
sched_param scheduling_parameters {};
|
||||
scheduling_parameters.sched_priority = priority;
|
||||
int result = pthread_setschedparam(m_tid, 0, &scheduling_parameters);
|
||||
if (result != 0)
|
||||
return Error::from_errno(result);
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<int> Threading::Thread::get_priority() const
|
||||
{
|
||||
sched_param scheduling_parameters {};
|
||||
int policy;
|
||||
int result = pthread_getschedparam(m_tid, &policy, &scheduling_parameters);
|
||||
if (result != 0)
|
||||
return Error::from_errno(result);
|
||||
return scheduling_parameters.sched_priority;
|
||||
}
|
||||
|
||||
void Threading::Thread::start()
|
||||
{
|
||||
int rc = pthread_create(
|
||||
|
|
|
@ -24,6 +24,9 @@ class Thread final : public Core::Object {
|
|||
public:
|
||||
virtual ~Thread();
|
||||
|
||||
ErrorOr<void> set_priority(int priority);
|
||||
ErrorOr<int> get_priority() const;
|
||||
|
||||
void start();
|
||||
void detach();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue