diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 31fbd36fe9e..a6c997d7f9c 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -54,6 +54,7 @@ qt_internal_add_module(Core global/qfloat16.cpp global/qfloat16.h global/qforeach.h global/qfunctionpointer.h + global/qgettid_p.h global/qglobal.cpp global/qglobal.h global/qglobal_p.h global/qglobalstatic.h global/qhooks.cpp global/qhooks_p.h diff --git a/src/corelib/global/qgettid_p.h b/src/corelib/global/qgettid_p.h new file mode 100644 index 00000000000..ab37ec09fae --- /dev/null +++ b/src/corelib/global/qgettid_p.h @@ -0,0 +1,61 @@ +// Copyright (C) 2025 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#ifndef QGETTID_P_H +#define QGETTID_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qglobal_p.h" + +#if defined(Q_OS_LINUX) && (defined(__GLIBC__) || __has_include()) +# include +# include + +# if defined(Q_OS_ANDROID) && !defined(SYS_gettid) +# define SYS_gettid __NR_gettid +# endif + +inline long qt_gettid() +{ + // no error handling + // this syscall has existed since Linux 2.4.11 and cannot fail + return syscall(SYS_gettid); +} +#elif defined(Q_OS_DARWIN) +# include +inline int qt_gettid() +{ + // no error handling: this call cannot fail + __uint64_t tid; + pthread_threadid_np(NULL, &tid); + return tid; +} +#elif defined(Q_OS_FREEBSD_KERNEL) && defined(__FreeBSD_version) && __FreeBSD_version >= 900031 +# include +inline int qt_gettid() +{ + return pthread_getthreadid_np(); +} +#else +# include +static QT_PREPEND_NAMESPACE(qint64) qt_gettid() +{ + QT_USE_NAMESPACE + return qintptr(QThread::currentThreadId()); +} +#endif + +QT_BEGIN_NAMESPACE +QT_END_NAMESPACE + +#endif // QGETTID_P_H diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 9e2451d101b..d224fbe6f68 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -21,6 +21,7 @@ #include "qthread.h" #include "private/qloggingregistry_p.h" #include "private/qcoreapplication_p.h" +#include "qgettid_p.h" #include #endif #ifdef Q_OS_WIN @@ -79,44 +80,6 @@ extern char *__progname; # include #endif // QLOGGING_USE_EXECINFO_BACKTRACE -#ifndef QT_BOOTSTRAPPED -#if defined(Q_OS_LINUX) && (defined(__GLIBC__) || __has_include()) -# include - -# if defined(Q_OS_ANDROID) && !defined(SYS_gettid) -# define SYS_gettid __NR_gettid -# endif - -static long qt_gettid() -{ - // no error handling - // this syscall has existed since Linux 2.4.11 and cannot fail - return syscall(SYS_gettid); -} -#elif defined(Q_OS_DARWIN) -# include -static int qt_gettid() -{ - // no error handling: this call cannot fail - __uint64_t tid; - pthread_threadid_np(NULL, &tid); - return tid; -} -#elif defined(Q_OS_FREEBSD_KERNEL) && defined(__FreeBSD_version) && __FreeBSD_version >= 900031 -# include -static int qt_gettid() -{ - return pthread_getthreadid_np(); -} -#else -static QT_PREPEND_NAMESPACE(qint64) qt_gettid() -{ - QT_USE_NAMESPACE - return qintptr(QThread::currentThreadId()); -} -#endif -#endif // !QT_BOOTSTRAPPED - #include #include #include