Skip to content

Commit 931a6b3

Browse files
committed
Add pthread_getname_np implementation for NDKs missing it
1 parent 08aa186 commit 931a6b3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

thirdparty/loguru/loguru.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@
8787
#ifndef LOGURU_STACKTRACES
8888
#define LOGURU_STACKTRACES 0
8989
#endif
90+
#if defined(__ANDROID__)
91+
// Some Android SDKs lack the pthread_getname_np function. Use prctl(PR_GET_NAME) instead
92+
// https://stackoverflow.com/a/32380917/73299
93+
// template<T> so NDKs with pthread_getname_np select the NDK function instead of this one
94+
#include <sys/prctl.h>
95+
template<typename T> inline int pthread_getname_np(T /*unused*/, char* buf, size_t buflen) {
96+
return prctl(PR_GET_NAME, reinterpret_cast<unsigned long>(buf), static_cast<unsigned long>(buflen), 0, 0);
97+
}
98+
#endif
99+
100+
90101
#else
91102
#define LOGURU_PTHREADS 1
92103
#define LOGURU_WINTHREADS 0

0 commit comments

Comments
 (0)