From eb8c09c104932d035ab28a73603136137f49dbee Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 24 Mar 2025 17:17:45 -0700 Subject: [PATCH] QThreadStorage: make the internal finish() function really private This class is very old and hasn't been modernized since C++98 became a thing we could rely on. We hadn't come up with the concept of private headers yet. This commit moves the exported QThreadStorageData::finish() function from the public header to QThreadStoragePrivate in a private header and no longer exports it. It also removes the need to pass the QList as a void **. Task-number: QTBUG-135044 Change-Id: I736cb12a7c29716effd7fffd87c7b086a8cb7e19 Reviewed-by: Volker Hilsheimer --- src/corelib/kernel/qcoreapplication.cpp | 3 +-- src/corelib/thread/qthread_unix.cpp | 3 +-- src/corelib/thread/qthread_win.cpp | 3 +-- src/corelib/thread/qthreadstorage.cpp | 5 ++--- src/corelib/thread/qthreadstorage.h | 1 - src/corelib/thread/qthreadstorage_p.h | 1 + 6 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 230f96e0ac8..6cf355aeaa9 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -491,8 +491,7 @@ void QCoreApplicationPrivate::cleanupThreadData() if (thisThreadData && !threadData_clean) { #if QT_CONFIG(thread) - void *data = &thisThreadData->tls; - QThreadStorageData::finish((void **)data); + QThreadStoragePrivate::finish(&thisThreadData->tls); #endif // need to clear the state of the mainData, just in case a new QCoreApplication comes along. diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 1710aecb8d6..8ea738ad874 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -460,8 +460,7 @@ void QThreadPrivate::finish() emit thr->finished(QThread::QPrivateSignal()); QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); - void *data = &d->data->tls; - QThreadStorageData::finish((void **)data); + QThreadStoragePrivate::finish(&d->data->tls); }); if constexpr (QT_CONFIG(broken_threadlocal_dtors)) diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index 746231b359e..ec752b7dce0 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -242,12 +242,11 @@ void QThreadPrivate::finish(bool lockAnyway) noexcept QMutexLocker locker(lockAnyway ? &d->mutex : nullptr); d->threadState = QThreadPrivate::Finishing; d->priority = QThread::InheritPriority; - void **tls_data = reinterpret_cast(&d->data->tls); if (lockAnyway) locker.unlock(); emit thr->finished(QThread::QPrivateSignal()); QCoreApplicationPrivate::sendPostedEvents(nullptr, QEvent::DeferredDelete, d->data); - QThreadStorageData::finish(tls_data); + QThreadStoragePrivate::finish(&d->data->tls); if (lockAnyway) locker.relock(); diff --git a/src/corelib/thread/qthreadstorage.cpp b/src/corelib/thread/qthreadstorage.cpp index d7f4b560a53..ba9efc0d56a 100644 --- a/src/corelib/thread/qthreadstorage.cpp +++ b/src/corelib/thread/qthreadstorage.cpp @@ -141,10 +141,9 @@ void QThreadStoragePrivate::init() destructors(); } -void QThreadStorageData::finish(void **p) +void QThreadStoragePrivate::finish(QList *tls) { - QList *tls = reinterpret_cast *>(p); - if (!tls || tls->isEmpty() || !destructors()) + if (tls->isEmpty() || !destructors()) return; // nothing to do DEBUG_MSG("QThreadStorageData: Destroying storage for thread %p", QThread::currentThread()); diff --git a/src/corelib/thread/qthreadstorage.h b/src/corelib/thread/qthreadstorage.h index 32dc29f0c26..839c91c779b 100644 --- a/src/corelib/thread/qthreadstorage.h +++ b/src/corelib/thread/qthreadstorage.h @@ -35,7 +35,6 @@ public: void** get() const; void** set(void* p); - static void finish(void**); int id; }; diff --git a/src/corelib/thread/qthreadstorage_p.h b/src/corelib/thread/qthreadstorage_p.h index d73b5a1d8e5..183b0e3f2d4 100644 --- a/src/corelib/thread/qthreadstorage_p.h +++ b/src/corelib/thread/qthreadstorage_p.h @@ -22,6 +22,7 @@ QT_BEGIN_NAMESPACE namespace QThreadStoragePrivate { void init(); +void finish(QList *tls); } // namespace QThreadStoragePrivate QT_END_NAMESPACE