summaryrefslogtreecommitdiffstats
path: root/src/dbus/qdbusintegrator.cpp
diff options
context:
space:
mode:
authorIevgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>2023-05-09 16:11:20 +0200
committerIevgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>2023-05-22 11:49:30 +0200
commit8d13a9e38715e1d39454fff579efed100eb49923 (patch)
treea16a30d92a2a00e08d86d20f07f64b535cd6b784 /src/dbus/qdbusintegrator.cpp
parentf99e5183274f01774d8b50024b0cd030a03c804f (diff)
QtDBus: Move dispatch enabling code into a single function
Remove the helper class. Change-Id: I82edd7fa1ce1d8b9044938a1378f992a40a0bbdf Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/dbus/qdbusintegrator.cpp')
-rw-r--r--src/dbus/qdbusintegrator.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp
index bd4b46fbda..c63d5bba93 100644
--- a/src/dbus/qdbusintegrator.cpp
+++ b/src/dbus/qdbusintegrator.cpp
@@ -293,12 +293,8 @@ static void qDBusNewConnection(DBusServer *server, DBusConnection *connection, v
// QDBusServer's thread in order to enable it after the
// QDBusServer::newConnection() signal has been received by the
// application's code
- newConnection->ref.ref();
QReadLocker serverLock(&serverConnection->lock);
- QDBusConnectionDispatchEnabler *o = new QDBusConnectionDispatchEnabler(newConnection);
- QMetaObject::invokeMethod(o, &QDBusConnectionDispatchEnabler::execute, Qt::QueuedConnection);
- if (serverConnection->serverObject)
- o->moveToThread(serverConnection->serverObject->thread());
+ newConnection->enableDispatchDelayed(serverConnection->serverObject);
}
void QDBusConnectionPrivate::_q_newConnection(QDBusConnectionPrivate *newConnection)
@@ -2656,6 +2652,28 @@ void QDBusConnectionPrivate::postEventToThread(int action, QObject *object, QEve
QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::AfterPost, this);
}
+/*
+ * Enable dispatch of D-Bus events for this connection, but only after
+ * context's thread's event loop has started and processed any already
+ * pending events. The event dispatch is then enabled in the DBus aux thread.
+ */
+void QDBusConnectionPrivate::enableDispatchDelayed(QObject *context)
+{
+ ref.ref();
+ QMetaObject::invokeMethod(
+ context,
+ [this]() {
+ // This call cannot race with something disabling dispatch only
+ // because dispatch is never re-disabled from Qt code on an
+ // in-use connection once it has been enabled.
+ QMetaObject::invokeMethod(
+ this, [this] { setDispatchEnabled(true); }, Qt::QueuedConnection);
+ if (!ref.deref())
+ deleteLater();
+ },
+ Qt::QueuedConnection);
+}
+
QT_END_NAMESPACE
#endif // QT_NO_DBUS