[core] Move set/get thread names to platform::

Android needs its own implementation.
This commit is contained in:
Thiago Marcos P. Santos
2016-07-15 15:01:16 +03:00
parent 5c037f4745
commit 4a1a7937ae
4 changed files with 33 additions and 29 deletions

View File

@@ -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;