diff --git a/runtime/vm/os_thread_absl.cc b/runtime/vm/os_thread_absl.cc index 9e61d0a0d49..7de84c49ba6 100644 --- a/runtime/vm/os_thread_absl.cc +++ b/runtime/vm/os_thread_absl.cc @@ -11,6 +11,9 @@ #include // NOLINT #include // NOLINT #include // NOLINT +#if defined(DART_HOST_OS_ANDROID) +#include +#endif // defined(DART_HOST_OS_ANDROID) #include "platform/address_sanitizer.h" #include "platform/assert.h" @@ -230,16 +233,16 @@ ThreadId OSThread::GetCurrentThreadTraceId() { #endif // SUPPORT_TIMELINE char* OSThread::GetCurrentThreadName() { -#if defined(DART_HOST_OS_ANDROID) - // TODO(derekx): |pthread_getname_np| isn't defined on Android, so we need to - // find an alternative solution. - return nullptr; -#elif defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_MACOS) const intptr_t kNameBufferSize = 16; char* name = static_cast(malloc(kNameBufferSize)); + +#if defined(DART_HOST_OS_ANDROID) + prctl(PR_GET_NAME, name); +#elif defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_MACOS) pthread_getname_np(pthread_self(), name, kNameBufferSize); - return name; #endif + + return name; } ThreadJoinId OSThread::GetCurrentThreadJoinId(OSThread* thread) { diff --git a/runtime/vm/os_thread_android.cc b/runtime/vm/os_thread_android.cc index 48554ee9f4e..45ceeb8626d 100644 --- a/runtime/vm/os_thread_android.cc +++ b/runtime/vm/os_thread_android.cc @@ -10,6 +10,7 @@ #include // NOLINT #include +#include #include // NOLINT #include // NOLINT @@ -218,9 +219,10 @@ ThreadId OSThread::GetCurrentThreadTraceId() { #endif // SUPPORT_TIMELINE char* OSThread::GetCurrentThreadName() { - // TODO(derekx): |pthread_getname_np| isn't defined on Android, so we need to - // find an alternative solution. - return nullptr; + const intptr_t kNameBufferSize = 16; + char* name = static_cast(malloc(kNameBufferSize)); + prctl(PR_GET_NAME, name); + return name; } ThreadJoinId OSThread::GetCurrentThreadJoinId(OSThread* thread) {