Fix accessing the thread id on Android

This commit is contained in:
Arvid Gerstmann 2018-07-24 13:43:25 +02:00
parent f04e67779c
commit 69dac3f611

View File

@ -7,8 +7,10 @@
#endif #endif
#ifdef __linux__ #ifdef __linux__
#include <syscall.h> # ifndef __ANDROID__
#include <fcntl.h> # include <syscall.h>
# endif
# include <fcntl.h>
#endif #endif
#include <inttypes.h> #include <inttypes.h>
@ -148,7 +150,11 @@ const char* GetThreadName( uint64_t id )
# elif defined __linux__ # elif defined __linux__
int cs, fd; int cs, fd;
char path[32]; char path[32];
# ifdef __ANDROID__
int tid = gettid();
# else
int tid = (int) syscall( SYS_gettid ); int tid = (int) syscall( SYS_gettid );
# endif
snprintf( path, sizeof( path ), "/proc/self/task/%d/comm", tid ); snprintf( path, sizeof( path ), "/proc/self/task/%d/comm", tid );
sprintf( buf, "%" PRIu64, id ); sprintf( buf, "%" PRIu64, id );
pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &cs ); pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &cs );