summaryrefslogtreecommitdiff
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
parent5c037f4745e5a9a3c5f5d050c59d39e3f763bb5a (diff)
downloadqtlocation-mapboxgl-4a1a7937ae795b46c885fd3edf871fe8cbb2468e.tar.gz
[core] Move set/get thread names to platform::
Android needs its own implementation.
-rw-r--r--include/mbgl/platform/platform.hpp6
-rw-r--r--platform/default/thread.cpp29
-rw-r--r--src/mbgl/platform/log.cpp2
-rw-r--r--src/mbgl/util/thread.hpp25
4 files changed, 33 insertions, 29 deletions
diff --git a/include/mbgl/platform/platform.hpp b/include/mbgl/platform/platform.hpp
index 59ba7f97f3..cc8327c470 100644
--- a/include/mbgl/platform/platform.hpp
+++ b/include/mbgl/platform/platform.hpp
@@ -14,6 +14,12 @@ std::string uppercase(const std::string &string);
// Lowercase a string, potentially using platform-specific routines.
std::string lowercase(const std::string &string);
+// Gets the name of the current thread.
+std::string getCurrentThreadName();
+
+// Set the name of the current thread, truncated at 15.
+void setCurrentThreadName(const std::string& name);
+
// Makes the current thread low priority.
void makeThreadLowPriority();
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;
diff --git a/src/mbgl/platform/log.cpp b/src/mbgl/platform/log.cpp
index 0f334ae3e7..b140485dd6 100644
--- a/src/mbgl/platform/log.cpp
+++ b/src/mbgl/platform/log.cpp
@@ -50,7 +50,7 @@ void Log::record(EventSeverity severity, Event event, int64_t code, const std::s
std::stringstream logStream;
- logStream << "{" << util::getCurrentThreadName() << "}";
+ logStream << "{" << platform::getCurrentThreadName() << "}";
logStream << "[" << Enum<Event>::toString(event) << "]";
if (code >= 0) {
diff --git a/src/mbgl/util/thread.hpp b/src/mbgl/util/thread.hpp
index 643d272b25..cd90e08049 100644
--- a/src/mbgl/util/thread.hpp
+++ b/src/mbgl/util/thread.hpp
@@ -86,29 +86,6 @@ private:
RunLoop* loop = nullptr;
};
-inline 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;
-}
-
-inline 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;
-}
-
template <class Object>
template <class... Args>
Thread<Object>::Thread(const ThreadContext& context, Args&&... args) {
@@ -117,7 +94,7 @@ Thread<Object>::Thread(const ThreadContext& context, Args&&... args) {
std::tuple<Args...> params = std::forward_as_tuple(::std::forward<Args>(args)...);
thread = std::thread([&] {
- setCurrentThreadName(context.name);
+ platform::setCurrentThreadName(context.name);
if (context.priority == ThreadPriority::Low) {
platform::makeThreadLowPriority();