Skip to content

Commit 14acd74

Browse files
committed
qt: Keep InitExecutor in main gui thread
1 parent 09cb5ec commit 14acd74

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

src/qt/initexecutor.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <qt/initexecutor.h>
66

77
#include <interfaces/node.h>
8+
#include <qt/guiutil.h>
89
#include <util/system.h>
910
#include <util/threadnames.h>
1011

@@ -18,7 +19,7 @@
1819
InitExecutor::InitExecutor(interfaces::Node& node)
1920
: QObject(), m_node(node)
2021
{
21-
this->moveToThread(&m_thread);
22+
m_context.moveToThread(&m_thread);
2223
m_thread.start();
2324
}
2425

@@ -38,29 +39,30 @@ void InitExecutor::handleRunawayException(const std::exception* e)
3839

3940
void InitExecutor::initialize()
4041
{
41-
try {
42-
util::ThreadRename("qt-init");
43-
qDebug() << __func__ << ": Running initialization in thread";
44-
interfaces::BlockAndHeaderTipInfo tip_info;
45-
bool rv = m_node.appInitMain(&tip_info);
46-
Q_EMIT initializeResult(rv, tip_info);
47-
} catch (const std::exception& e) {
48-
handleRunawayException(&e);
49-
} catch (...) {
50-
handleRunawayException(nullptr);
51-
}
42+
GUIUtil::ObjectInvoke(&m_context, [this] {
43+
try {
44+
util::ThreadRename("qt-init");
45+
interfaces::BlockAndHeaderTipInfo tip_info;
46+
bool rv = m_node.appInitMain(&tip_info);
47+
Q_EMIT initializeResult(rv, tip_info);
48+
} catch (const std::exception& e) {
49+
handleRunawayException(&e);
50+
} catch (...) {
51+
handleRunawayException(nullptr);
52+
}
53+
});
5254
}
5355

5456
void InitExecutor::shutdown()
5557
{
56-
try {
57-
qDebug() << __func__ << ": Running Shutdown in thread";
58-
m_node.appShutdown();
59-
qDebug() << __func__ << ": Shutdown finished";
60-
Q_EMIT shutdownResult();
61-
} catch (const std::exception& e) {
62-
handleRunawayException(&e);
63-
} catch (...) {
64-
handleRunawayException(nullptr);
65-
}
58+
GUIUtil::ObjectInvoke(&m_context, [this] {
59+
try {
60+
m_node.appShutdown();
61+
Q_EMIT shutdownResult();
62+
} catch (const std::exception& e) {
63+
handleRunawayException(&e);
64+
} catch (...) {
65+
handleRunawayException(nullptr);
66+
}
67+
});
6668
}

src/qt/initexecutor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public Q_SLOTS:
4040
void handleRunawayException(const std::exception* e);
4141

4242
interfaces::Node& m_node;
43+
QObject m_context;
4344
QThread m_thread;
4445
};
4546

src/qt/test/test_main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <interfaces/init.h>
1010
#include <interfaces/node.h>
1111
#include <qt/bitcoin.h>
12-
#include <qt/initexecutor.h>
1312
#include <qt/test/apptests.h>
1413
#include <qt/test/rpcnestedtests.h>
1514
#include <qt/test/uritests.h>

0 commit comments

Comments
 (0)