Skip to content

Commit

Permalink
QThreadData: inline ref() and deref()
Browse files Browse the repository at this point in the history
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.

Pick-to: 6.8
Change-Id: I2bb6e519239ea33cc521fffd71f57574f940ed62
Reviewed-by: Fabian Kosmale <[email protected]>
  • Loading branch information
thiagomacieira committed Nov 22, 2024
1 parent 296b46f commit 278d225
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
16 changes: 0 additions & 16 deletions src/corelib/thread/qthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,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);
Expand Down
18 changes: 15 additions & 3 deletions src/corelib/thread/qthread_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,21 @@ class QThreadData
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();
Expand Down

0 comments on commit 278d225

Please sign in to comment.