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 <volker.hilsheimer@qt.io>
This commit is contained in:
Thiago Macieira 2025-03-24 17:17:45 -07:00
parent 81a7a4c2d9
commit eb8c09c104
6 changed files with 6 additions and 10 deletions

View File

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

View File

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

View File

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

View File

@ -141,10 +141,9 @@ void QThreadStoragePrivate::init()
destructors();
}
void QThreadStorageData::finish(void **p)
void QThreadStoragePrivate::finish(QList<void *> *tls)
{
QList<void *> *tls = reinterpret_cast<QList<void *> *>(p);
if (!tls || tls->isEmpty() || !destructors())
if (tls->isEmpty() || !destructors())
return; // nothing to do
DEBUG_MSG("QThreadStorageData: Destroying storage for thread %p", QThread::currentThread());

View File

@ -35,7 +35,6 @@ public:
void** get() const;
void** set(void* p);
static void finish(void**);
int id;
};

View File

@ -22,6 +22,7 @@ QT_BEGIN_NAMESPACE
namespace QThreadStoragePrivate {
void init();
void finish(QList<void *> *tls);
} // namespace QThreadStoragePrivate
QT_END_NAMESPACE