From f1211d328ec3646d2ed51c6208eb5b812887287c Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Fri, 8 Sep 2017 17:49:00 +0100 Subject: [PATCH] Delete QDBusServiceWatcher when unloading X-Plane driver. Summary: When unloading a sim driver, first its threads are killed, then the driver object is destroyed. This means that when the `QDBusServiceWatcher` child object is destroyed, it deadlocks waiting for a thread that was already killed (T147). This change causes the `QDBusServiceWatcher` to be deleted before the driver is unloaded. Reviewers: #swift_pilot_client, kbasan, rwinklmeier Reviewed By: #swift_pilot_client, kbasan, rwinklmeier Subscribers: kbasan, jenkins Tags: #swift_pilot_client Differential Revision: https://dev.swift-project.org/D50 --- src/plugins/simulator/xplane/simulatorxplane.cpp | 15 +++++++++++---- src/plugins/simulator/xplane/simulatorxplane.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 328bfe2b7..1df81812a 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -113,6 +113,13 @@ namespace BlackSimPlugin resetData(); } + void CSimulatorXPlane::unload() + { + CSimulatorCommon::unload(); + delete m_watcher; + m_watcher = nullptr; + } + // convert xplane squawk mode to swift squawk mode BlackMisc::Aviation::CTransponder::TransponderMode xpdrMode(int xplaneMode, bool ident) { @@ -255,7 +262,7 @@ namespace BlackSimPlugin connect(m_traffic, &CXSwiftBusTrafficProxy::installedModelsUpdated, this, &CSimulatorXPlane::ps_installedModelsUpdated); m_service->updateAirportsInRange(); m_traffic->updateInstalledModels(); - m_watcher->setConnection(m_conn); + if (m_watcher) { m_watcher->setConnection(m_conn); } loadCslPackages(); emitSimulatorCombinedStatus(); return true; @@ -276,7 +283,7 @@ namespace BlackSimPlugin } m_conn = QDBusConnection { "default" }; - m_watcher->setConnection(m_conn); + if (m_watcher) { m_watcher->setConnection(m_conn); } delete m_service; delete m_traffic; delete m_weather; @@ -290,7 +297,7 @@ namespace BlackSimPlugin void CSimulatorXPlane::ps_serviceUnregistered() { m_conn = QDBusConnection { "default" }; - m_watcher->setConnection(m_conn); + if (m_watcher) { m_watcher->setConnection(m_conn); } delete m_service; delete m_traffic; delete m_weather; @@ -746,7 +753,7 @@ namespace BlackSimPlugin { if (m_watcher) { - m_watcher->deleteLater(); + delete m_watcher; m_watcher = nullptr; } } diff --git a/src/plugins/simulator/xplane/simulatorxplane.h b/src/plugins/simulator/xplane/simulatorxplane.h index 6f81d43c4..69022e98f 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.h +++ b/src/plugins/simulator/xplane/simulatorxplane.h @@ -100,6 +100,7 @@ namespace BlackSimPlugin virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) override; virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override { return BlackMisc::PhysicalQuantities::CTime(0, BlackMisc::PhysicalQuantities::CTimeUnit::hrmin()); } virtual bool setInterpolatorMode(BlackMisc::Simulation::CInterpolatorMulti::Mode mode, const BlackMisc::Aviation::CCallsign &callsign) override; + virtual void unload() override; //! @} //! Creates an appropriate dbus connection from the string describing it