From 8843b5de2b9df3bc45255f2c97c267cfda141595 Mon Sep 17 00:00:00 2001 From: Mark Washeim Date: Thu, 7 Apr 2022 09:48:57 +0200 Subject: [PATCH] ownership, concurrency and and destructor for parser backend manager and cherry picked: https://github.com/smurfy/fahrplan/pull/269 --- src/fahrplan_backend_manager.cpp | 10 +++++++++- src/fahrplan_parser_thread.h | 2 +- src/parser/parser_abstract.cpp | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/fahrplan_backend_manager.cpp b/src/fahrplan_backend_manager.cpp index 6831aab..f9c90c3 100644 --- a/src/fahrplan_backend_manager.cpp +++ b/src/fahrplan_backend_manager.cpp @@ -26,6 +26,14 @@ FahrplanBackendManager::FahrplanBackendManager(int defaultParser, QObject *paren currentParserIndex = defaultParser; } +FahrplanBackendManager::~FahrplanBackendManager() +{ + if (m_parser) { + // Parser object will be autodeleted after the thread quits. + m_parser->quit(); + } +} + QStringList FahrplanBackendManager::getParserList() { QStringList result; @@ -73,7 +81,7 @@ void FahrplanBackendManager::setParser(int index) m_parser->quit(); } - m_parser = new FahrplanParserThread(); + m_parser = new FahrplanParserThread(this); m_parser->init(index); // Init can fallback to another index if its invalid. diff --git a/src/fahrplan_parser_thread.h b/src/fahrplan_parser_thread.h index 4ede625..b8c0e9d 100644 --- a/src/fahrplan_parser_thread.h +++ b/src/fahrplan_parser_thread.h @@ -91,7 +91,7 @@ public slots: void run(); private: - bool m_ready; + volatile bool m_ready; int i_parser; QStringList m_trainrestrictions; diff --git a/src/parser/parser_abstract.cpp b/src/parser/parser_abstract.cpp index a1fa468..a97c1ea 100644 --- a/src/parser/parser_abstract.cpp +++ b/src/parser/parser_abstract.cpp @@ -67,7 +67,7 @@ ParserAbstract::ParserAbstract(QObject *parent) : ParserAbstract::~ParserAbstract() { - //clearJourney(); + clearJourney(); delete requestTimeout; delete NetworkManager; }