1#include <mbgl/util/platform.hpp>
2#include <mbgl/util/logging.hpp>
3
4#include <string>
5
6#include <pthread.h>
7#include <sched.h>
8
9namespace mbgl {
10namespace platform {
11
12std::string getCurrentThreadName() {
13 char name[32] = "unknown";
14 pthread_getname_np(target_thread: pthread_self(), buf: name, buflen: sizeof(name));
15
16 return name;
17}
18
19void setCurrentThreadName(const std::string& name) {
20 if (name.size() > 15) { // Linux hard limit (see manpages).
21 pthread_setname_np(target_thread: pthread_self(), name: name.substr(pos: 0, n: 15).c_str());
22 } else {
23 pthread_setname_np(target_thread: pthread_self(), name: name.c_str());
24 }
25}
26
27void makeThreadLowPriority() {
28 struct sched_param param;
29 param.sched_priority = 0;
30
31 if (sched_setscheduler(pid: 0, SCHED_IDLE, param: &param) != 0) {
32 Log::Warning(event: Event::General, args: "Couldn't set thread scheduling policy");
33 }
34}
35
36} // namespace platform
37} // namespace mbgl
38

source code of qtlocation/src/3rdparty/mapbox-gl-native/platform/default/thread.cpp