From 2612e6d802071f8c012fb9ca530a9478bba253ea Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 27 Jan 2020 09:03:53 +0100 Subject: Use Linux gettid as available since glibc 2.30 Change-Id: I793f91a1fe601cff367be7c178f4e712f0f97117 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87488 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- sal/osl/unx/thread.cxx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/sal/osl/unx/thread.cxx b/sal/osl/unx/thread.cxx index b47e13bf49ed..ab19bdc8aa5b 100644 --- a/sal/osl/unx/thread.cxx +++ b/sal/osl/unx/thread.cxx @@ -21,6 +21,7 @@ #include #include +#include #include #include "system.hxx" @@ -30,6 +31,7 @@ #include #endif #include +#include #include #include #include @@ -649,10 +651,19 @@ static oslThreadIdentifier insertThreadId (pthread_t hThread) pEntry->Handle = hThread; #if defined LINUX && ! defined __FreeBSD_kernel__ - long lin_tid = syscall(SYS_gettid); - if (SAL_MAX_UINT32 < static_cast(lin_tid)) +#if defined __GLIBC__ && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 30)) + // gettid returns a pid_t, which POSIX defines to be a signed integer type; assume that all + // valid pid_t values on Linux are positive (zero is filtered out in the generic code + // below): + pid_t const tid = gettid(); + assert(tid >= 0); +#else + long const tid = syscall(SYS_gettid); + if (tid < 0 || o3tl::make_unsigned(tid) > std::numeric_limits::max()) { std::abort(); - pEntry->Ident = static_cast(lin_tid); + } +#endif + pEntry->Ident = tid; #elif defined MACOSX || defined IOS // currently the value of pthread_threadid_np is the same then // syscall(SYS_thread_selfid), which returns an int as the TID. -- cgit