Skip to content

Commit

Permalink
PORT: Call gettid via its glibc wrapper if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesjer authored and JanWielemaker committed Sep 17, 2024
1 parent 01d7ccf commit 0c5d0ad
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
31 changes: 20 additions & 11 deletions cmake/Config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -343,22 +343,31 @@ check_pthread_setname_np()
endif(HAVE_PTHREAD_SETNAME_NP)

check_c_source_compiles(
"#include <sys/types.h>
#include <linux/unistd.h>
"#define _GNU_SOURCE
#include <unistd.h>
int main()
{ _syscall0(pid_t,gettid);
return 0;
{ return gettid();
}"
HAVE_GETTID_MACRO)
if(NOT HAVE_GETTID_MACRO)
HAVE_GETTID_FUNCTION)
if(NOT HAVE_GETTID_FUNCTION)
check_c_source_compiles(
"#include <unistd.h>
#include <sys/syscall.h>
"#include <sys/types.h>
#include <linux/unistd.h>
int main()
{ syscall(__NR_gettid);
return 0;
{ _syscall0(pid_t,gettid);
return 0;
}"
HAVE_GETTID_SYSCALL)
HAVE_GETTID_MACRO)
if(NOT HAVE_GETTID_FUNCTION AND NOT HAVE_GETTID_MACRO)
check_c_source_compiles(
"#include <unistd.h>
#include <sys/syscall.h>
int main()
{ syscall(__NR_gettid);
return 0;
}"
HAVE_GETTID_SYSCALL)
endif()
endif()

endif(CMAKE_USE_PTHREADS_INIT)
Expand Down
9 changes: 8 additions & 1 deletion src/pl-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,18 @@ APPROACH
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

#if defined(__linux__)
#ifdef HAVE_GETTID_FUNCTION
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <unistd.h>
#else
#include <syscall.h>
#ifdef HAVE_GETTID_MACRO
_syscall0(pid_t,gettid)
#endif
#endif
#endif

#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
Expand Down Expand Up @@ -1935,7 +1942,7 @@ set_system_thread_id(PL_thread_info_t *info)
info->has_tid = TRUE;
#if defined(HAVE_GETTID_SYSCALL)
info->pid = syscall(__NR_gettid);
#elif defined(HAVE_GETTID_MACRO)
#elif defined(HAVE_GETTID_FUNCTION) || defined(HAVE_GETTID_MACRO)
info->pid = gettid();
#elif defined(__CYGWIN__)
info->pid = getpid();
Expand Down

0 comments on commit 0c5d0ad

Please sign in to comment.