QSignalSpy: make args member const
This means it's implicitly thread-safe now and we don't need to protect accesses to it with the mutex. Task-number: QTBUG-123544 Change-Id: I9f826003dca6fb81e7a75e283482c81ecff09be0 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
This commit is contained in:
parent
951bf6e3ec
commit
46ad7fe966
@ -258,7 +258,6 @@ bool QSignalSpy::connectToSignal(const QObject *sender, int sigIndex)
|
||||
|
||||
void QSignalSpy::appendArgs(void **a)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
QList<QVariant> list;
|
||||
list.reserve(args.size());
|
||||
for (qsizetype i = 0; i < args.size(); ++i) {
|
||||
@ -268,6 +267,7 @@ void QSignalSpy::appendArgs(void **a)
|
||||
else
|
||||
list << QVariant(QMetaType(type), a[i + 1]);
|
||||
}
|
||||
QMutexLocker locker(&m_mutex);
|
||||
append(std::move(list));
|
||||
|
||||
if (m_waiting) {
|
||||
|
@ -12,8 +12,6 @@
|
||||
#include <QtCore/qvariant.h>
|
||||
#include <QtCore/qmutex.h>
|
||||
|
||||
#include <mutex>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
@ -65,15 +63,11 @@ public:
|
||||
|
||||
private:
|
||||
explicit QSignalSpy(ObjectSignal os)
|
||||
: args(os.obj ? makeArgs(os.sig, os.obj) : QList<int>{})
|
||||
{
|
||||
if (!os.obj)
|
||||
return;
|
||||
|
||||
auto tmp = makeArgs(os.sig, os.obj);
|
||||
{
|
||||
const auto lock = std::scoped_lock(m_mutex);
|
||||
args = std::move(tmp);
|
||||
}
|
||||
if (!connectToSignal(os.obj, os.sig.methodIndex()))
|
||||
return;
|
||||
|
||||
@ -92,11 +86,11 @@ private:
|
||||
// the full, normalized signal name
|
||||
QByteArray sig;
|
||||
// holds the QMetaType types for the argument list of the signal
|
||||
QList<int> args;
|
||||
const QList<int> args;
|
||||
|
||||
QTestEventLoop m_loop;
|
||||
bool m_waiting = false;
|
||||
QMutex m_mutex; // protects m_waiting, args and the QList base class, between appendArgs() and wait()
|
||||
QMutex m_mutex; // protects m_waiting and the QList base class, between appendArgs() and wait()
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
Loading…
x
Reference in New Issue
Block a user