qlogging.cpp: move the qt_gettid() function to a header

Just for code organization.

Change-Id: Ifa5da67b98f07f669e4ffffd1a0fc10b4087b6b2
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
This commit is contained in:
Thiago Macieira 2025-01-14 15:32:08 -08:00
parent e90115b5f7
commit e3ca467f40
3 changed files with 63 additions and 38 deletions

View File

@ -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

View File

@ -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(<sys/syscall.h>))
# include <sys/syscall.h>
# include <unistd.h>
# 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 <pthread.h>
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 <pthread_np.h>
inline int qt_gettid()
{
return pthread_getthreadid_np();
}
#else
# include <qthread.h>
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

View File

@ -21,6 +21,7 @@
#include "qthread.h"
#include "private/qloggingregistry_p.h"
#include "private/qcoreapplication_p.h"
#include "qgettid_p.h"
#include <qtcore_tracepoints_p.h>
#endif
#ifdef Q_OS_WIN
@ -79,44 +80,6 @@ extern char *__progname;
# include <cxxabi.h>
#endif // QLOGGING_USE_EXECINFO_BACKTRACE
#ifndef QT_BOOTSTRAPPED
#if defined(Q_OS_LINUX) && (defined(__GLIBC__) || __has_include(<sys/syscall.h>))
# include <sys/syscall.h>
# 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 <pthread.h>
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 <pthread_np.h>
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 <cstdlib>
#include <algorithm>
#include <chrono>