summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorozaykova <[email protected]>2023-02-01 14:06:22 +0300
committerozaykova <[email protected]>2023-02-01 14:06:22 +0300
commit99bf72df7c096ea5a2b9015d3bfe4b84fc02c469 (patch)
tree5817a254542a2619c20ef505b696c25b527a1f7d
parente586e630d0fa60533135bae70fce3613feab9a85 (diff)
SetLowestThreadPriority in util
-rw-r--r--util/system/thread.cpp15
-rw-r--r--util/system/thread.h1
2 files changed, 16 insertions, 0 deletions
diff --git a/util/system/thread.cpp b/util/system/thread.cpp
index aa2a4fc9ddc..e9c3da3d113 100644
--- a/util/system/thread.cpp
+++ b/util/system/thread.cpp
@@ -43,6 +43,21 @@ bool SetHighestThreadPriority() {
#endif
}
+bool SetLowestThreadPriority() {
+#ifdef _win_
+ return SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST);
+#else
+ struct sched_param sch;
+ memset(&sch, 0, sizeof(sch));
+ sch.sched_priority = 0;
+ #ifdef _darwin_
+ return pthread_setschedparam(pthread_self(), SCHED_RR, &sch) == 0;
+ #else
+ return pthread_setschedparam(pthread_self(), SCHED_IDLE, &sch) == 0;
+ #endif
+#endif
+}
+
namespace {
using TParams = TThread::TParams;
using TId = TThread::TId;
diff --git a/util/system/thread.h b/util/system/thread.h
index a6e8abdb5be..830c98a5c30 100644
--- a/util/system/thread.h
+++ b/util/system/thread.h
@@ -11,6 +11,7 @@
#include "progname.h"
bool SetHighestThreadPriority();
+bool SetLowestThreadPriority();
class TThread {
template <typename Callable>