diff options
author | João Barbosa <joao.paulo.barbosa@gmail.com> | 2021-09-26 15:11:46 +0100 |
---|---|---|
committer | João Barbosa <joao.paulo.barbosa@gmail.com> | 2021-09-27 13:05:40 +0100 |
commit | 03a5fe06bd85111ef844a30dcfdf3b317ff74517 (patch) | |
tree | fafa724b4a7f0bea23d38e1d4ff1aa8169646cc3 /src/qt | |
parent | 09cb5ec6c8b4468ee3e8c2b3e1a9075907e5c84d (diff) | |
download | bitcoin-03a5fe06bd85111ef844a30dcfdf3b317ff74517.tar.xz |
qt: Keep InitExecutor in main gui thread
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/initexecutor.cpp | 49 | ||||
-rw-r--r-- | src/qt/initexecutor.h | 1 | ||||
-rw-r--r-- | src/qt/test/test_main.cpp | 1 |
3 files changed, 28 insertions, 23 deletions
diff --git a/src/qt/initexecutor.cpp b/src/qt/initexecutor.cpp index 7060f74dab..24ae7ba73d 100644 --- a/src/qt/initexecutor.cpp +++ b/src/qt/initexecutor.cpp @@ -5,6 +5,7 @@ #include <qt/initexecutor.h> #include <interfaces/node.h> +#include <qt/guiutil.h> #include <util/system.h> #include <util/threadnames.h> @@ -18,7 +19,7 @@ InitExecutor::InitExecutor(interfaces::Node& node) : QObject(), m_node(node) { - this->moveToThread(&m_thread); + m_context.moveToThread(&m_thread); m_thread.start(); } @@ -38,29 +39,33 @@ void InitExecutor::handleRunawayException(const std::exception* e) void InitExecutor::initialize() { - try { - util::ThreadRename("qt-init"); - qDebug() << __func__ << ": Running initialization in thread"; - interfaces::BlockAndHeaderTipInfo tip_info; - bool rv = m_node.appInitMain(&tip_info); - Q_EMIT initializeResult(rv, tip_info); - } catch (const std::exception& e) { - handleRunawayException(&e); - } catch (...) { - handleRunawayException(nullptr); - } + GUIUtil::ObjectInvoke(&m_context, [this] { + try { + util::ThreadRename("qt-init"); + qDebug() << "Running initialization in thread"; + interfaces::BlockAndHeaderTipInfo tip_info; + bool rv = m_node.appInitMain(&tip_info); + Q_EMIT initializeResult(rv, tip_info); + } catch (const std::exception& e) { + handleRunawayException(&e); + } catch (...) { + handleRunawayException(nullptr); + } + }); } void InitExecutor::shutdown() { - try { - qDebug() << __func__ << ": Running Shutdown in thread"; - m_node.appShutdown(); - qDebug() << __func__ << ": Shutdown finished"; - Q_EMIT shutdownResult(); - } catch (const std::exception& e) { - handleRunawayException(&e); - } catch (...) { - handleRunawayException(nullptr); - } + GUIUtil::ObjectInvoke(&m_context, [this] { + try { + qDebug() << "Running Shutdown in thread"; + m_node.appShutdown(); + qDebug() << "Shutdown finished"; + Q_EMIT shutdownResult(); + } catch (const std::exception& e) { + handleRunawayException(&e); + } catch (...) { + handleRunawayException(nullptr); + } + }); } diff --git a/src/qt/initexecutor.h b/src/qt/initexecutor.h index 319ce40465..410c44fa2d 100644 --- a/src/qt/initexecutor.h +++ b/src/qt/initexecutor.h @@ -40,6 +40,7 @@ private: void handleRunawayException(const std::exception* e); interfaces::Node& m_node; + QObject m_context; QThread m_thread; }; diff --git a/src/qt/test/test_main.cpp b/src/qt/test/test_main.cpp index 884ed25637..55d00bb37e 100644 --- a/src/qt/test/test_main.cpp +++ b/src/qt/test/test_main.cpp @@ -9,7 +9,6 @@ #include <interfaces/init.h> #include <interfaces/node.h> #include <qt/bitcoin.h> -#include <qt/initexecutor.h> #include <qt/test/apptests.h> #include <qt/test/rpcnestedtests.h> #include <qt/test/uritests.h> |