diff options
author | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2020-01-31 17:01:12 +0200 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2020-02-06 23:54:19 +0200 |
commit | 4be2fa4f9af29cfad869412d2d794964554d4eba (patch) | |
tree | 94d2b3f93457242930f43a2171714c5ce06634df /platform | |
parent | 5789faf11ae2a740927bce599a209883a78b113e (diff) | |
download | qtlocation-mapboxgl-4be2fa4f9af29cfad869412d2d794964554d4eba.tar.gz |
[core] Add platform::setCurrentThreadPriority(double)
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/src/thread.cpp | 8 | ||||
-rw-r--r-- | platform/darwin/src/nsthread.mm | 10 | ||||
-rw-r--r-- | platform/default/src/mbgl/util/thread.cpp | 19 | ||||
-rw-r--r-- | platform/qt/src/thread.cpp | 2 |
4 files changed, 36 insertions, 3 deletions
diff --git a/platform/android/src/thread.cpp b/platform/android/src/thread.cpp index cd0a72306e..f480fc5d43 100644 --- a/platform/android/src/thread.cpp +++ b/platform/android/src/thread.cpp @@ -40,6 +40,14 @@ void makeThreadLowPriority() { setpriority(PRIO_PROCESS, 0, 19); } +void setCurrentThreadPriority(double priority) { + if (priority < -20 || priority > 19) { + Log::Warning(Event::General, "Couldn't set thread priority"); + return; + } + setpriority(PRIO_PROCESS, 0, int(priority)); +} + void attachThread() { using namespace android; assert(env == nullptr); diff --git a/platform/darwin/src/nsthread.mm b/platform/darwin/src/nsthread.mm index f7edcdf5d6..9af9cf3cc4 100644 --- a/platform/darwin/src/nsthread.mm +++ b/platform/darwin/src/nsthread.mm @@ -1,5 +1,6 @@ #import <Foundation/Foundation.h> +#include <mbgl/util/logging.hpp> #include <mbgl/util/platform.hpp> #include <mbgl/platform/thread.hpp> @@ -24,6 +25,15 @@ void makeThreadLowPriority() { [[NSThread currentThread] setThreadPriority:0.0]; } +void setCurrentThreadPriority(double priority) { + if (priority > 1.0 || priority < 0.0) { + Log::Warning(Event::General, "Invalid thread priority was provided"); + return; + } + + [[NSThread currentThread] setThreadPriority:priority]; +} + void attachThread() { } diff --git a/platform/default/src/mbgl/util/thread.cpp b/platform/default/src/mbgl/util/thread.cpp index 58a7c12bc8..1ee5b12119 100644 --- a/platform/default/src/mbgl/util/thread.cpp +++ b/platform/default/src/mbgl/util/thread.cpp @@ -6,6 +6,7 @@ #include <pthread.h> #include <sched.h> +#include <sys/resource.h> namespace mbgl { namespace platform { @@ -40,11 +41,23 @@ void makeThreadLowPriority() { #endif } -void attachThread() { -} +void setCurrentThreadPriority(double priority) { + if (setpriority(PRIO_PROCESS, 0, int(priority)) < 0) { + Log::Warning(Event::General, "Couldn't set thread priority"); + } -void detachThread() { +#ifdef SCHED_OTHER + struct sched_param param; + param.sched_priority = 0; + if (sched_setscheduler(0, SCHED_OTHER, ¶m) != 0) { + Log::Warning(Event::General, "Couldn't set thread scheduling policy"); + } +#endif } +void attachThread() {} + +void detachThread() {} + } // namespace platform } // namespace mbgl diff --git a/platform/qt/src/thread.cpp b/platform/qt/src/thread.cpp index 103b6d74f1..6c7d14042d 100644 --- a/platform/qt/src/thread.cpp +++ b/platform/qt/src/thread.cpp @@ -16,6 +16,8 @@ void setCurrentThreadName(const std::string&) { void makeThreadLowPriority() { } +void setCurrentThreadPriority(double) {} + void attachThread() { } |