diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2020-01-27 09:03:53 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2020-01-27 11:45:50 +0100 |
commit | 2612e6d802071f8c012fb9ca530a9478bba253ea (patch) | |
tree | 062ce03f6eeea41147ea96a2db0b18e249a48bb5 /sal | |
parent | dd98cb655f243024260dd45c44b751e564c1c67e (diff) |
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 <sbergman@redhat.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/osl/unx/thread.cxx | 17 |
1 files 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 <cassert> #include <cstddef> +#include <limits> #include <functional> #include "system.hxx" @@ -30,6 +31,7 @@ #include <sched.h> #endif #include <config_options.h> +#include <o3tl/safeint.hxx> #include <osl/thread.h> #include <osl/nlsupport.h> #include <rtl/textenc.h> @@ -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<unsigned long>(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<sal_uInt32>::max()) { std::abort(); - pEntry->Ident = static_cast<pid_t>(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. |