[threading] Linux fixes on setting an incorrect priority
This call was failing since SCHED_FIFO doesn't support negative priorities, but only positive ones, see third paragraph of scheduling policies: https://man7.org/linux/man-pages/man7/sched.7.html. Additionally Linux do provice up to 99 levels, but I've limited myself to the required UNIX standard of 32, and split the priority levels evenly from that. I've also added a couple of rows to debug additional issues in the future like this.
This commit is contained in:
parent
4d7b30e844
commit
55bbb28a80
|
@ -402,6 +402,7 @@ class Timer : public WaitHandle {
|
|||
virtual bool Cancel() = 0;
|
||||
};
|
||||
|
||||
#if XE_PLATFORM_WINDOWS
|
||||
struct ThreadPriority {
|
||||
static const int32_t kLowest = -2;
|
||||
static const int32_t kBelowNormal = -1;
|
||||
|
@ -409,6 +410,15 @@ struct ThreadPriority {
|
|||
static const int32_t kAboveNormal = 1;
|
||||
static const int32_t kHighest = 2;
|
||||
};
|
||||
#else
|
||||
struct ThreadPriority {
|
||||
static const int32_t kLowest = 1;
|
||||
static const int32_t kBelowNormal = 8;
|
||||
static const int32_t kNormal = 16;
|
||||
static const int32_t kAboveNormal = 24;
|
||||
static const int32_t kHighest = 32;
|
||||
};
|
||||
#endif
|
||||
|
||||
// Models a Win32-like thread object.
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms682453(v=vs.85).aspx
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include <ctime>
|
||||
#include <memory>
|
||||
|
||||
#include "logging.h"
|
||||
|
||||
#if XE_PLATFORM_ANDROID
|
||||
#include <dlfcn.h>
|
||||
|
||||
|
@ -660,8 +662,18 @@ class PosixCondition<Thread> : public PosixConditionBase {
|
|||
WaitStarted();
|
||||
sched_param param{};
|
||||
param.sched_priority = new_priority;
|
||||
if (pthread_setschedparam(thread_, SCHED_FIFO, ¶m) != 0)
|
||||
assert_always();
|
||||
int res = pthread_setschedparam(thread_, SCHED_FIFO, ¶m);
|
||||
if (res != 0) {
|
||||
switch (res) {
|
||||
case EPERM:
|
||||
XELOGW("Permission denied while setting priority");
|
||||
break;
|
||||
case EINVAL:
|
||||
assert_always();
|
||||
default:
|
||||
XELOGW("Unknown error while setting priority");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QueueUserCallback(std::function<void()> callback) {
|
||||
|
|
Loading…
Reference in New Issue