diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 77e58abfa2..a0e4450d28 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -420,6 +420,16 @@ bool QObjectPrivate::maybeSignalConnected(uint signalIndex) const return false; } +/*! + \internal + */ +QAbstractMetaCallEvent::~QAbstractMetaCallEvent() +{ +#if QT_CONFIG(thread) + if (semaphore_) + semaphore_->release(); +#endif +} /*! \internal @@ -427,8 +437,8 @@ bool QObjectPrivate::maybeSignalConnected(uint signalIndex) const QMetaCallEvent::QMetaCallEvent(ushort method_offset, ushort method_relative, QObjectPrivate::StaticMetaCallFunction callFunction, const QObject *sender, int signalId, int nargs, int *types, void **args, QSemaphore *semaphore) - : QEvent(MetaCall), slotObj_(0), sender_(sender), signalId_(signalId), - nargs_(nargs), types_(types), args_(args), semaphore_(semaphore), + : QAbstractMetaCallEvent(sender, signalId, semaphore), + slotObj_(nullptr), nargs_(nargs), types_(types), args_(args), callFunction_(callFunction), method_offset_(method_offset), method_relative_(method_relative) { } @@ -437,9 +447,9 @@ QMetaCallEvent::QMetaCallEvent(ushort method_offset, ushort method_relative, QOb */ QMetaCallEvent::QMetaCallEvent(QtPrivate::QSlotObjectBase *slotO, const QObject *sender, int signalId, int nargs, int *types, void **args, QSemaphore *semaphore) - : QEvent(MetaCall), slotObj_(slotO), sender_(sender), signalId_(signalId), - nargs_(nargs), types_(types), args_(args), semaphore_(semaphore), - callFunction_(0), method_offset_(0), method_relative_(ushort(-1)) + : QAbstractMetaCallEvent(sender, signalId, semaphore), + slotObj_(slotO), nargs_(nargs), types_(types), args_(args), + callFunction_(nullptr), method_offset_(0), method_relative_(ushort(-1)) { if (slotObj_) slotObj_->ref(); @@ -458,10 +468,6 @@ QMetaCallEvent::~QMetaCallEvent() free(types_); free(args_); } -#if QT_CONFIG(thread) - if (semaphore_) - semaphore_->release(); -#endif if (slotObj_) slotObj_->destroyIfLastRef(); } @@ -1179,7 +1185,7 @@ bool QObject::event(QEvent *e) case QEvent::MetaCall: { - QMetaCallEvent *mce = static_cast(e); + QAbstractMetaCallEvent *mce = static_cast(e); if (!d_func()->connections.load()) { QBasicMutexLocker locker(signalSlotLock(this)); diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h index 2c1502c2a0..da3d035087 100644 --- a/src/corelib/kernel/qobject_p.h +++ b/src/corelib/kernel/qobject_p.h @@ -485,7 +485,26 @@ Q_DECLARE_TYPEINFO(QObjectPrivate::Connection, Q_MOVABLE_TYPE); Q_DECLARE_TYPEINFO(QObjectPrivate::Sender, Q_MOVABLE_TYPE); class QSemaphore; -class Q_CORE_EXPORT QMetaCallEvent : public QEvent +class Q_CORE_EXPORT QAbstractMetaCallEvent : public QEvent +{ +public: + QAbstractMetaCallEvent(const QObject *sender, int signalId, QSemaphore *semaphore = nullptr) + : QEvent(MetaCall), signalId_(signalId), sender_(sender), semaphore_(semaphore) + {} + ~QAbstractMetaCallEvent(); + + virtual void placeMetaCall(QObject *object) = 0; + + inline const QObject *sender() const { return sender_; } + inline int signalId() const { return signalId_; } + +private: + int signalId_; + const QObject *sender_; + QSemaphore *semaphore_; +}; + +class Q_CORE_EXPORT QMetaCallEvent : public QAbstractMetaCallEvent { public: QMetaCallEvent(ushort method_offset, ushort method_relative, QObjectPrivate::StaticMetaCallFunction callFunction , const QObject *sender, int signalId, @@ -496,23 +515,18 @@ public: QMetaCallEvent(QtPrivate::QSlotObjectBase *slotObj, const QObject *sender, int signalId, int nargs = 0, int *types = nullptr, void **args = nullptr, QSemaphore *semaphore = nullptr); - ~QMetaCallEvent(); + ~QMetaCallEvent() override; inline int id() const { return method_offset_ + method_relative_; } - inline const QObject *sender() const { return sender_; } - inline int signalId() const { return signalId_; } inline void **args() const { return args_; } - virtual void placeMetaCall(QObject *object); + virtual void placeMetaCall(QObject *object) override; private: QtPrivate::QSlotObjectBase *slotObj_; - const QObject *sender_; - int signalId_; int nargs_; int *types_; void **args_; - QSemaphore *semaphore_; QObjectPrivate::StaticMetaCallFunction callFunction_; ushort method_offset_; ushort method_relative_; diff --git a/src/dbus/qdbusabstractinterface.cpp b/src/dbus/qdbusabstractinterface.cpp index 148bd54147..d49959d8e2 100644 --- a/src/dbus/qdbusabstractinterface.cpp +++ b/src/dbus/qdbusabstractinterface.cpp @@ -66,11 +66,11 @@ namespace { // of to QDBusAbstractInterface::customEvent. // See solution in Patch Set 1 of this change in the Qt Gerrit servers. // (https://codereview.qt-project.org/#/c/126384/1) -class DisconnectRelayEvent : public QMetaCallEvent +class DisconnectRelayEvent : public QAbstractMetaCallEvent { public: DisconnectRelayEvent(QObject *sender, const QMetaMethod &m) - : QMetaCallEvent(0, 0, nullptr, sender, m.methodIndex()) + : QAbstractMetaCallEvent(sender, m.methodIndex()) {} void placeMetaCall(QObject *object) override diff --git a/src/dbus/qdbusintegrator_p.h b/src/dbus/qdbusintegrator_p.h index 0f7e00fde0..44789b3317 100644 --- a/src/dbus/qdbusintegrator_p.h +++ b/src/dbus/qdbusintegrator_p.h @@ -101,36 +101,37 @@ struct QDBusSlotCache Q_DECLARE_SHARED(QDBusSlotCache::Data) Q_DECLARE_SHARED(QDBusSlotCache) -class QDBusCallDeliveryEvent: public QMetaCallEvent +class QDBusCallDeliveryEvent: public QAbstractMetaCallEvent { public: QDBusCallDeliveryEvent(const QDBusConnection &c, int id, QObject *sender, const QDBusMessage &msg, const QVector &types, int f = 0) - : QMetaCallEvent(0, id, nullptr, sender, -1), connection(c), message(msg), metaTypes(types), flags(f) + : QAbstractMetaCallEvent(sender, -1), connection(c), message(msg), metaTypes(types), id(id), flags(f) { } void placeMetaCall(QObject *object) override { - QDBusConnectionPrivate::d(connection)->deliverCall(object, flags, message, metaTypes, id()); + QDBusConnectionPrivate::d(connection)->deliverCall(object, flags, message, metaTypes, id); } private: QDBusConnection connection; // just for refcounting QDBusMessage message; QVector metaTypes; + int id; int flags; }; -class QDBusActivateObjectEvent: public QMetaCallEvent +class QDBusActivateObjectEvent: public QAbstractMetaCallEvent { public: QDBusActivateObjectEvent(const QDBusConnection &c, QObject *sender, const QDBusConnectionPrivate::ObjectTreeNode &n, int p, const QDBusMessage &m, QSemaphore *s = nullptr) - : QMetaCallEvent(0, ushort(-1), nullptr, sender, -1, 0, nullptr, nullptr, s), connection(c), node(n), + : QAbstractMetaCallEvent(sender, -1, s), connection(c), node(n), pathStartPos(p), message(m), handled(false) { } - ~QDBusActivateObjectEvent(); + ~QDBusActivateObjectEvent() override; void placeMetaCall(QObject *) override; @@ -142,15 +143,15 @@ private: bool handled; }; -class QDBusSpyCallEvent : public QMetaCallEvent +class QDBusSpyCallEvent : public QAbstractMetaCallEvent { public: typedef void (*Hook)(const QDBusMessage&); QDBusSpyCallEvent(QDBusConnectionPrivate *cp, const QDBusConnection &c, const QDBusMessage &msg, const Hook *hooks, int count) - : QMetaCallEvent(0, 0, nullptr, cp, 0), conn(c), msg(msg), hooks(hooks), hookCount(count) + : QAbstractMetaCallEvent(cp, 0), conn(c), msg(msg), hooks(hooks), hookCount(count) {} - ~QDBusSpyCallEvent(); + ~QDBusSpyCallEvent() override; void placeMetaCall(QObject *) override; static inline void invokeSpyHooks(const QDBusMessage &msg, const Hook *hooks, int hookCount);