Revert "QObject: attempt to fix a deadlock introduced by an earlier fix"

This reverts commit 22d4c67234.

Reason for revert: The fix causes crashes
tst_QObjectRace::disconnectRace2 and we don't currently have a
clear resolution on further fixes.

Task-number: QTBUG-107034
Change-Id: I310c27654f125cdb2939940d432724e73c89f485
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Mårten Nordheim 2022-10-14 12:54:13 +00:00
parent 0d915623ec
commit e48c0a6e7c

View File

@ -5311,20 +5311,11 @@ bool QObjectPrivate::disconnect(const QObject *sender, int signal_index, const Q
/*!
\internal
\threadsafe
Thread-safety warning: this function may be called from any thread and is
thread-safe, \b{so long as the sender is not being deleted}. At the time of
this writing, this function is called from QObject::disconnect() and from
the multiple places where a single-shot connection is activated; in both
cases, the construction of the user code is already such that the sender
object cannot be undergoing deletion in another thread.
*/
inline bool QObjectPrivate::removeConnection(QObjectPrivate::Connection *c)
{
if (!c)
return false;
// double-checked locking on this pointer
QObject *receiver = c->receiver.loadRelaxed();
if (!receiver)
return false;
@ -5345,6 +5336,7 @@ inline bool QObjectPrivate::removeConnection(QObjectPrivate::Connection *c)
Q_ASSERT(connections);
connections->removeConnection(c);
c->sender->disconnectNotify(QMetaObjectPrivate::signal(c->sender->metaObject(), c->signal_index));
// We must not hold the receiver mutex, else we risk dead-locking; we also only need the sender mutex
// It is however vital to hold the senderMutex before calling cleanOrphanedConnections, as otherwise
// another thread might modify/delete the connection
@ -5356,8 +5348,6 @@ inline bool QObjectPrivate::removeConnection(QObjectPrivate::Connection *c)
locker.dismiss(); // so we dismiss the QOrderedMutexLocker
}
// this is safe if the condition in the documentation is correct
c->sender->disconnectNotify(QMetaObjectPrivate::signal(c->sender->metaObject(), c->signal_index));
return true;
}