summaryrefslogtreecommitdiff
path: root/platform/default
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2016-07-15 15:01:16 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2016-07-16 10:38:42 +0300
commit4a1a7937ae795b46c885fd3edf871fe8cbb2468e (patch)
treebcfd0c424e67d876ed5a61d30eaafede2ad116a5 /platform/default
parent5c037f4745e5a9a3c5f5d050c59d39e3f763bb5a (diff)
downloadqtlocation-mapboxgl-4a1a7937ae795b46c885fd3edf871fe8cbb2468e.tar.gz
[core] Move set/get thread names to platform::
Android needs its own implementation.
Diffstat (limited to 'platform/default')
-rw-r--r--platform/default/thread.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/platform/default/thread.cpp b/platform/default/thread.cpp
index 3ef3257923..d398bc926b 100644
--- a/platform/default/thread.cpp
+++ b/platform/default/thread.cpp
@@ -1,16 +1,37 @@
#include <mbgl/platform/platform.hpp>
-
#include <mbgl/platform/log.hpp>
+#include <string>
+
#include <pthread.h>
-#ifdef __linux__
-#include <linux/sched.h>
-#endif
#include <sched.h>
namespace mbgl {
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)
+ pthread_setname_np(pthread_self(), name.c_str());
+#endif
+#endif
+ (void)name;
+}
+
void makeThreadLowPriority() {
#ifdef SCHED_IDLE
struct sched_param param;