RIP QBasicMutexLocker

This was used as a work-around for Q5MutexLocker's UB downcasting
QBasicMutex to QMutex, and for some unspecified performance
improvements.

Now that Q6MutexLocker is a template, the two are almost
token-by-token identical, so we can remove this work-around and use
QMutexLocker directly.

Partially reverts aea500d5d7.

Pick-to: 6.6 6.5 6.2
Change-Id: I57ef5c53999869aa3454fbbaad884c1d18591b2a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2023-06-13 11:37:13 +02:00
parent 166e792269
commit 8d39b21655
2 changed files with 12 additions and 43 deletions

View File

@ -234,7 +234,7 @@ bool QObjectPrivate::isSender(const QObject *receiver, const char *signal) const
ConnectionData *cd = connections.loadRelaxed();
if (signal_index < 0 || !cd)
return false;
QBasicMutexLocker locker(signalSlotLock(q));
QMutexLocker locker(signalSlotLock(q));
if (signal_index < cd->signalVectorCount()) {
const QObjectPrivate::Connection *c = cd->signalVector.loadRelaxed()->at(signal_index).first.loadRelaxed();
@ -274,7 +274,7 @@ QObjectList QObjectPrivate::senderList() const
QObjectList returnValue;
ConnectionData *cd = connections.loadRelaxed();
if (cd) {
QBasicMutexLocker locker(signalSlotLock(q_func()));
QMutexLocker locker(signalSlotLock(q_func()));
for (Connection *c = cd->senders; c; c = c->next)
returnValue << c->sender;
}
@ -1025,7 +1025,7 @@ QObject::~QObject()
}
QBasicMutex *signalSlotMutex = signalSlotLock(this);
QBasicMutexLocker locker(signalSlotMutex);
QMutexLocker locker(signalSlotMutex);
// disconnect all receivers
int receiverCount = cd->signalVectorCount();
@ -1383,7 +1383,7 @@ bool QObject::event(QEvent *e)
QAbstractMetaCallEvent *mce = static_cast<QAbstractMetaCallEvent*>(e);
if (!d_func()->connections.loadRelaxed()) {
QBasicMutexLocker locker(signalSlotLock(this));
QMutexLocker locker(signalSlotLock(this));
d_func()->ensureConnectionData();
}
QObjectPrivate::Sender sender(this, const_cast<QObject*>(mce->sender()), mce->signalId());
@ -2523,7 +2523,7 @@ QObject *QObject::sender() const
{
Q_D(const QObject);
QBasicMutexLocker locker(signalSlotLock(this));
QMutexLocker locker(signalSlotLock(this));
QObjectPrivate::ConnectionData *cd = d->connections.loadRelaxed();
if (!cd || !cd->currentSender)
return nullptr;
@ -2565,7 +2565,7 @@ int QObject::senderSignalIndex() const
{
Q_D(const QObject);
QBasicMutexLocker locker(signalSlotLock(this));
QMutexLocker locker(signalSlotLock(this));
QObjectPrivate::ConnectionData *cd = d->connections.loadRelaxed();
if (!cd || !cd->currentSender)
return -1;
@ -2630,7 +2630,7 @@ int QObject::receivers(const char *signal) const
}
QObjectPrivate::ConnectionData *cd = d->connections.loadRelaxed();
QBasicMutexLocker locker(signalSlotLock(this));
QMutexLocker locker(signalSlotLock(this));
if (cd && signal_index < cd->signalVectorCount()) {
const QObjectPrivate::Connection *c = cd->signalVector.loadRelaxed()->at(signal_index).first.loadRelaxed();
while (c) {
@ -2677,7 +2677,7 @@ bool QObject::isSignalConnected(const QMetaMethod &signal) const
signalIndex += QMetaObjectPrivate::signalOffset(signal.mobj);
QBasicMutexLocker locker(signalSlotLock(this));
QMutexLocker locker(signalSlotLock(this));
return d->isSignalConnected(signalIndex, true);
}
@ -3583,7 +3583,7 @@ bool QMetaObjectPrivate::disconnect(const QObject *sender,
QObject *s = const_cast<QObject *>(sender);
QBasicMutex *senderMutex = signalSlotLock(sender);
QBasicMutexLocker locker(senderMutex);
QMutexLocker locker(senderMutex);
QObjectPrivate::ConnectionData *scd = QObjectPrivate::get(s)->connections.loadRelaxed();
if (!scd)
@ -3810,7 +3810,7 @@ static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connect
while (argumentTypes[nargs - 1])
++nargs;
QBasicMutexLocker locker(signalSlotLock(c->receiver.loadRelaxed()));
QMutexLocker locker(signalSlotLock(c->receiver.loadRelaxed()));
QObject *receiver = c->receiver.loadRelaxed();
if (!receiver) {
// the connection has been disconnected before we got the lock
@ -3951,7 +3951,7 @@ void doActivate(QObject *sender, int signal_index, void **argv)
QSemaphore semaphore;
{
QBasicMutexLocker locker(signalSlotLock(receiver));
QMutexLocker locker(signalSlotLock(receiver));
if (!c->isSingleShot && !c->receiver.loadAcquire())
continue;
QMetaCallEvent *ev = c->isSlotObject ?
@ -4272,7 +4272,7 @@ void QObject::dumpObjectInfo() const
objectName().isEmpty() ? "unnamed" : objectName().toLocal8Bit().data());
Q_D(const QObject);
QBasicMutexLocker locker(signalSlotLock(this));
QMutexLocker locker(signalSlotLock(this));
// first, look for connections where this object is the sender
qDebug(" SIGNALS OUT");

View File

@ -118,35 +118,6 @@ private:
bool locked;
};
class QBasicMutexLocker
{
public:
inline explicit QBasicMutexLocker(QBasicMutex *m) QT_MUTEX_LOCK_NOEXCEPT
: m(m), isLocked(true)
{
m->lock();
}
inline ~QBasicMutexLocker() { if (isLocked) unlock(); }
inline void unlock() noexcept
{
isLocked = false;
m->unlock();
}
inline void relock() QT_MUTEX_LOCK_NOEXCEPT
{
isLocked = true;
m->lock();
}
private:
Q_DISABLE_COPY(QBasicMutexLocker)
QBasicMutex *m;
bool isLocked;
};
#else
class [[nodiscard]] QOrderedMutexLocker
@ -167,8 +138,6 @@ public:
static bool relock(QBasicMutex *, QBasicMutex *) { return false; }
};
using QBasicMutexLocker = QMutexLocker<QBasicMutex>;
#endif