From 3f7d309a1c4979e4ab0394521faf959d33457f04 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 13 Nov 2024 11:43:27 -0800 Subject: [PATCH] QThreadData: inline ref() and deref() You *should* be using LTO if you want performance, but these functions are trivial enough that it makes sense to inline them. The !QT_CONFIG(thread) support seems wrong and is probably leaking memory for the QAdoptedThread for the main thread. But since that only happens because the program is exiting anyway, it's a case of "leak" in quotes and one I don't care about. Change-Id: I2bb6e519239ea33cc521fffd71f57574f940ed62 Reviewed-by: Fabian Kosmale (cherry picked from commit 278d2255e25d659ce5be08d2b81226556b1dfee2) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/thread/qthread.cpp | 16 ---------------- src/corelib/thread/qthread_p.h | 18 +++++++++++++++--- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index 5e37739a1eb..7de449c16cc 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -94,22 +94,6 @@ QThreadData::~QThreadData() // fprintf(stderr, "QThreadData %p destroyed\n", this); } -void QThreadData::ref() -{ -#if QT_CONFIG(thread) - (void) _ref.ref(); - Q_ASSERT(_ref.loadRelaxed() != 0); -#endif -} - -void QThreadData::deref() -{ -#if QT_CONFIG(thread) - if (!_ref.deref()) - delete this; -#endif -} - QAbstractEventDispatcher *QThreadData::createEventDispatcher() { QAbstractEventDispatcher *ed = QThreadPrivate::createEventDispatcher(this); diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h index afb10fbf9ac..abd789eab6d 100644 --- a/src/corelib/thread/qthread_p.h +++ b/src/corelib/thread/qthread_p.h @@ -296,9 +296,21 @@ public: static QThreadData *get2(QThread *thread) { Q_ASSERT_X(thread != nullptr, "QThread", "internal error"); return thread->d_func()->data; } - - void ref(); - void deref(); +#if QT_CONFIG(thread) + void ref() + { + (void) _ref.ref(); + Q_ASSERT(_ref.loadRelaxed() != 0); + } + void deref() + { + if (!_ref.deref()) + delete this; + } +#else + void ref() {} + void deref() {} +#endif inline bool hasEventDispatcher() const { return eventDispatcher.loadRelaxed() != nullptr; } QAbstractEventDispatcher *createEventDispatcher();