This commit is contained in:
hoholee12 2024-09-19 01:06:24 +02:00 committed by GitHub
commit 866f91f0fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 0 deletions

View File

@ -53,6 +53,8 @@ DYNAMIC_IMPORT_RENAME("Kernel32.dll", SetThreadDescriptionImport, "SetThreadDesc
#include <sys/syscall.h>
#include <sys/timerfd.h>
#include <unistd.h>
#include <sys/syscall.h>
#define gettid() syscall(SYS_gettid)
#endif
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
@ -3090,6 +3092,24 @@ void thread_ctrl::set_native_priority(int priority)
{
sig_log.error("SetThreadPriority() failed: %s", fmt::win_error{GetLastError(), nullptr});
}
#elif defined(__linux__)
// available niceness for root: -20~19
id_t threadpid = gettid();
uid_t euid = geteuid();
if (euid == 0)
{
int linuxprio = 0;
if (priority > 0)
linuxprio = -6;
else if (priority < 0)
linuxprio = 6;
if (int err = setpriority(PRIO_PROCESS, threadpid, linuxprio))
{
sig_log.error("setpriority(%d, %d) failed: %d", threadpid, linuxprio, err);
}
}
#else
int policy;
struct sched_param param;