[android] Set thread name properly
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
'src/log_android.cpp',
|
||||
'src/http_file_source.cpp',
|
||||
'src/asset_file_source.cpp',
|
||||
'../default/thread.cpp',
|
||||
'src/thread.cpp',
|
||||
'../default/string_stdlib.cpp',
|
||||
'../default/image.cpp',
|
||||
'../default/png_reader.cpp',
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "run_loop_impl.hpp"
|
||||
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
#include <mbgl/util/thread_context.hpp>
|
||||
#include <mbgl/util/thread_local.hpp>
|
||||
#include <mbgl/util/timer.hpp>
|
||||
@@ -75,7 +76,7 @@ private:
|
||||
|
||||
RunLoop::Impl::Impl(RunLoop* runLoop_, RunLoop::Type type) : runLoop(runLoop_) {
|
||||
using namespace mbgl::android;
|
||||
detach = attach_jni_thread(theJVM, &env, "");
|
||||
detach = attach_jni_thread(theJVM, &env, platform::getCurrentThreadName());
|
||||
|
||||
loop = ALooper_prepare(0);
|
||||
assert(loop);
|
||||
|
||||
37
platform/android/src/thread.cpp
Normal file
37
platform/android/src/thread.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <mbgl/platform/log.hpp>
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
// Implementation based on Chromium's platform_thread_android.cc.
|
||||
|
||||
namespace mbgl {
|
||||
namespace platform {
|
||||
|
||||
std::string getCurrentThreadName() {
|
||||
char name[32] = "unknown";
|
||||
|
||||
if (prctl(PR_GET_NAME, name) == -1) {
|
||||
Log::Warning(Event::General, "Couldn't get thread name");
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
void setCurrentThreadName(const std::string& name) {
|
||||
if (prctl(PR_SET_NAME, name.c_str()) == -1) {
|
||||
Log::Warning(Event::General, "Couldn't set thread name");
|
||||
}
|
||||
}
|
||||
|
||||
void makeThreadLowPriority() {
|
||||
// ANDROID_PRIORITY_LOWEST = 19
|
||||
//
|
||||
// Supposedly would set the priority for the whole process, but
|
||||
// on Linux/Android it only sets for the current thread.
|
||||
setpriority(PRIO_PROCESS, 0, 19);
|
||||
}
|
||||
|
||||
} // namespace platform
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user