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 <fabian.kosmale@qt.io>
(cherry picked from commit 278d2255e25d659ce5be08d2b81226556b1dfee2)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Thiago Macieira 2024-11-13 11:43:27 -08:00 committed by Qt Cherry-pick Bot
parent 027ee82051
commit 3f7d309a1c
2 changed files with 15 additions and 19 deletions

View File

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

View File

@ -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();