summaryrefslogtreecommitdiff
path: root/platform/default/src/mbgl/util/thread.cpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2018-12-13 18:45:29 +0100
committerKonstantin Käfer <mail@kkaefer.com>2018-12-14 11:03:03 +0100
commit1d8235f5b899a2cd8414522b2d72b96fab91577b (patch)
tree2ab56dce064de872525db7f24ba150a9065c4757 /platform/default/src/mbgl/util/thread.cpp
parentc2a4a8822ce9577c972975da61034a30fb0fe3e9 (diff)
downloadqtlocation-mapboxgl-1d8235f5b899a2cd8414522b2d72b96fab91577b.tar.gz
[build] rework platform/default directory and add -files.txt for vendored libs
Diffstat (limited to 'platform/default/src/mbgl/util/thread.cpp')
-rw-r--r--platform/default/src/mbgl/util/thread.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/platform/default/src/mbgl/util/thread.cpp b/platform/default/src/mbgl/util/thread.cpp
new file mode 100644
index 0000000000..c7c79b4fb0
--- /dev/null
+++ b/platform/default/src/mbgl/util/thread.cpp
@@ -0,0 +1,37 @@
+#include <mbgl/util/platform.hpp>
+#include <mbgl/util/logging.hpp>
+
+#include <string>
+
+#include <pthread.h>
+#include <sched.h>
+
+namespace mbgl {
+namespace platform {
+
+std::string getCurrentThreadName() {
+ char name[32] = "unknown";
+ pthread_getname_np(pthread_self(), name, sizeof(name));
+
+ return name;
+}
+
+void setCurrentThreadName(const std::string& name) {
+ if (name.size() > 15) { // Linux hard limit (see manpages).
+ pthread_setname_np(pthread_self(), name.substr(0, 15).c_str());
+ } else {
+ pthread_setname_np(pthread_self(), name.c_str());
+ }
+}
+
+void makeThreadLowPriority() {
+ struct sched_param param;
+ param.sched_priority = 0;
+
+ if (sched_setscheduler(0, SCHED_IDLE, &param) != 0) {
+ Log::Warning(Event::General, "Couldn't set thread scheduling policy");
+ }
+}
+
+} // namespace platform
+} // namespace mbgl