From ad0d876b18ab3f9715c5679eabba761efbfe37ed Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 15 Aug 2017 09:03:10 +0300 Subject: [PATCH] Added support --cpu-priority support for Linux. --- src/Platform_unix.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/Platform_unix.cpp b/src/Platform_unix.cpp index 861fe8732..0873e954c 100644 --- a/src/Platform_unix.cpp +++ b/src/Platform_unix.cpp @@ -22,7 +22,9 @@ */ +#include #include +#include #include @@ -65,12 +67,51 @@ void Platform::release() void Platform::setProcessPriority(int priority) { - } void Platform::setThreadPriority(int priority) { + if (priority == -1) { + return; + } + int prio = 19; + switch (priority) + { + case 1: + prio = 5; + break; + + case 2: + prio = 0; + break; + + case 3: + prio = -5; + break; + + case 4: + prio = -10; + break; + + case 5: + prio = -15; + break; + + default: + break; + } + + setpriority(PRIO_PROCESS, 0, prio); + + if (priority == 0) { + sched_param param; + param.sched_priority = 0; + + if (sched_setscheduler(0, SCHED_IDLE, ¶m) != 0) { + sched_setscheduler(0, SCHED_BATCH, ¶m); + } + } }