diff options
Diffstat (limited to 'platform/default/src/mbgl/util/thread.cpp')
-rw-r--r-- | platform/default/src/mbgl/util/thread.cpp | 37 |
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, ¶m) != 0) { + Log::Warning(Event::General, "Couldn't set thread scheduling policy"); + } +} + +} // namespace platform +} // namespace mbgl |