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 9 namespace mbgl { 10 namespace platform { 11 getCurrentThreadName()12std::string getCurrentThreadName() { 13 char name[32] = "unknown"; 14 pthread_getname_np(pthread_self(), name, sizeof(name)); 15 16 return name; 17 } 18 setCurrentThreadName(const std::string & name)19void setCurrentThreadName(const std::string& name) { 20 if (name.size() > 15) { // Linux hard limit (see manpages). 21 pthread_setname_np(pthread_self(), name.substr(0, 15).c_str()); 22 } else { 23 pthread_setname_np(pthread_self(), name.c_str()); 24 } 25 } 26 makeThreadLowPriority()27void makeThreadLowPriority() { 28 struct sched_param param; 29 param.sched_priority = 0; 30 31 if (sched_setscheduler(0, SCHED_IDLE, ¶m) != 0) { 32 Log::Warning(Event::General, "Couldn't set thread scheduling policy"); 33 } 34 } 35 36 } // namespace platform 37 } // namespace mbgl 38