Skip to content

Commit

Permalink
perfschema: use glibc gettid if available
Browse files Browse the repository at this point in the history
  • Loading branch information
grooverdan committed Jun 1, 2021
1 parent 68eac8a commit 90adf2a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmake/os/WindowsCache.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ SET(HAVE_SCHED_GETCPU CACHE INTERNAL "")
SET(HAVE_NANOSLEEP CACHE INTERNAL "")
SET(HAVE_PTHREAD_THREADID_NP CACHE INTERNAL "")
SET(HAVE_SYS_GETTID CACHE INTERNAL "")
SET(HAVE_GETTID CACHE INTERNAL "")
SET(HAVE_INTEGER_PTHREAD_SELF CACHE INTERNAL "")
SET(HAVE_PTHREAD_GETTHREADID_NP CACHE INTERNAL "")
SET(HAVE_TIMER_DELETE CACHE INTERNAL "")
Expand Down
3 changes: 3 additions & 0 deletions storage/perfschema/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ int main(int ac, char **av)
}"
HAVE_PTHREAD_THREADID_NP)

# gettid() library function (glibc-2.30+)
CHECK_SYMBOL_EXISTS(gettid unistd.h HAVE_GETTID)

# Check for gettid() system call
CHECK_C_SOURCE_COMPILES("
#include <sys/types.h>
Expand Down
11 changes: 7 additions & 4 deletions storage/perfschema/my_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ static inline my_thread_os_id_t my_thread_os_id()
pthread_threadid_np(nullptr, &tid64);
return (pid_t)tid64;
#else
#ifdef HAVE_GETTID
/* Linux glibc-2.30+ */
return gettid();
#else
#ifdef HAVE_SYS_GETTID
/*
Linux.
Linux before glibc-2.30
See man gettid
See GLIBC Bug 6399 - gettid() should have a wrapper
https://sourceware.org/bugzilla/show_bug.cgi?id=6399
*/
return syscall(SYS_gettid);
#else
Expand All @@ -82,7 +84,8 @@ static inline my_thread_os_id_t my_thread_os_id()
#endif /* HAVE_PTHREAD_GETTHREADID_NP */
#endif /* _WIN32 */
#endif /* HAVE_SYS_GETTID */
#endif /* HAVE_SYS_THREAD_SELFID */
#endif /* HAVE_GETTID */
#endif /* HAVE_PTHREAD_THREADID_NP */
}

#define CHANNEL_NAME_LENGTH MAX_CONNECTION_NAME
Expand Down
1 change: 1 addition & 0 deletions storage/perfschema/pfs_config.h.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#cmakedefine HAVE_PTHREAD_THREADID_NP 1
#cmakedefine HAVE_SYS_GETTID 1
#cmakedefine HAVE_GETTID
#cmakedefine HAVE_GETTHRID 1
#cmakedefine HAVE_PTHREAD_GETTHREADID_NP 1
#cmakedefine HAVE_INTEGER_PTHREAD_SELF 1

0 comments on commit 90adf2a

Please sign in to comment.