diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-07-15 19:43:47 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-07-16 10:38:42 +0300 |
commit | e23d8adf8c7942950b0cf28d35efa25ec9fdff13 (patch) | |
tree | c56595c5499f5ea1aec950a0f2678cdac745ed42 | |
parent | d52faadf73d8b66e39b1d5fde5d20d3cdce12d8c (diff) | |
download | qtlocation-mapboxgl-e23d8adf8c7942950b0cf28d35efa25ec9fdff13.tar.gz |
[core] Clean-up threading #ifdefs
-rw-r--r-- | platform/darwin/src/nsthread.mm | 13 | ||||
-rw-r--r-- | platform/default/thread.cpp | 22 |
2 files changed, 16 insertions, 19 deletions
diff --git a/platform/darwin/src/nsthread.mm b/platform/darwin/src/nsthread.mm index 9ac1d2caa0..eee6d6991b 100644 --- a/platform/darwin/src/nsthread.mm +++ b/platform/darwin/src/nsthread.mm @@ -2,9 +2,22 @@ #include <mbgl/platform/platform.hpp> +#include <pthread.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) { + pthread_setname_np(name.c_str()); +} + void makeThreadLowPriority() { [[NSThread currentThread] setThreadPriority:0.0]; } diff --git a/platform/default/thread.cpp b/platform/default/thread.cpp index a217bc73f4..f4d0b9a855 100644 --- a/platform/default/thread.cpp +++ b/platform/default/thread.cpp @@ -11,42 +11,26 @@ namespace platform { std::string getCurrentThreadName() { char name[32] = "unknown"; -#if defined(__APPLE__) pthread_getname_np(pthread_self(), name, sizeof(name)); -#elif defined(__GLIBC__) && defined(__GLIBC_PREREQ) -#if __GLIBC_PREREQ(2, 12) - pthread_getname_np(pthread_self(), name, sizeof(name)); -#endif -#endif + return name; } void setCurrentThreadName(const std::string& name) { -#if defined(__APPLE__) - pthread_setname_np(name.c_str()); -#elif defined(__GLIBC__) && defined(__GLIBC_PREREQ) -#if __GLIBC_PREREQ(2, 12) 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()); } -#endif -#endif - (void)name; } void makeThreadLowPriority() { -#ifdef SCHED_IDLE struct sched_param param; param.sched_priority = 0; - int status = sched_setscheduler(0, SCHED_IDLE, ¶m); - if (status != 0) { + + if (sched_setscheduler(0, SCHED_IDLE, ¶m) != 0) { Log::Warning(Event::General, "Couldn't set thread scheduling policy"); } -#else -#pragma message("Building without thread priority control") -#endif } } // namespace platform |