1// Copyright (C) 2025 Intel Corporation.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QGETTID_P_H
5#define QGETTID_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qglobal_p.h"
19
20#if defined(Q_OS_LINUX) && (defined(__GLIBC__) || __has_include(<sys/syscall.h>))
21# include <sys/syscall.h>
22# include <unistd.h>
23
24# if defined(Q_OS_ANDROID) && !defined(SYS_gettid)
25# define SYS_gettid __NR_gettid
26# endif
27
28static inline long qt_gettid()
29{
30 // no error handling
31 // this syscall has existed since Linux 2.4.11 and cannot fail
32 return syscall(SYS_gettid);
33}
34#elif defined(Q_OS_DARWIN)
35# include <pthread.h>
36static inline int qt_gettid()
37{
38 // no error handling: this call cannot fail
39 __uint64_t tid;
40 pthread_threadid_np(NULL, &tid);
41 return tid;
42}
43#elif defined(Q_OS_FREEBSD_KERNEL) && defined(__FreeBSD_version) && __FreeBSD_version >= 900031
44# include <pthread_np.h>
45static inline int qt_gettid()
46{
47 return pthread_getthreadid_np();
48}
49#else
50# include <qthread.h>
51static QT_PREPEND_NAMESPACE(qint64) qt_gettid()
52{
53 QT_USE_NAMESPACE
54 return qintptr(QThread::currentThreadId());
55}
56#endif
57
58QT_BEGIN_NAMESPACE
59QT_END_NAMESPACE
60
61#endif // QGETTID_P_H
62

source code of qtbase/src/corelib/global/qgettid_p.h