Allow reading QObject::objectName from other threads again

The new binding system made it impossible to read from non-owning threads,
but we have code that did so with external locking. This patch makes it
safe again, assuming all reads and writes are locked. This is left
intentionally undocumented.

Pick-to: 6.3 6.2
Task-number: QTBUG-99775
Change-Id: I845afa5d545ca0ac762ac369181b1497dac52195
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2022-01-12 10:47:19 +01:00 committed by Volker Hilsheimer
parent d83dbc3db2
commit 3f32dcd1dd

View File

@ -1245,6 +1245,10 @@ QObjectPrivate::Connection::~Connection()
QString QObject::objectName() const
{
Q_D(const QObject);
#if QT_CONFIG(thread)
if (QThread::currentThreadId() != d->threadData.loadRelaxed()->threadId.loadRelaxed()) // Unsafe code path
return d->extraData ? d->extraData->objectName.valueBypassingBindings() : QString();
#endif
if (!d->extraData && QtPrivate::isAnyBindingEvaluating()) {
QObjectPrivate *dd = const_cast<QObjectPrivate *>(d);
// extraData is mutable, so this should be safe