mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-29 18:20:58 +02:00
Merge bitcoin-core/gui#434: Keep InitExecutor in main gui thread
03a5fe06bd
qt: Keep InitExecutor in main gui thread (João Barbosa) Pull request description: The `InitExecutor` constructor moves the instance to a dedicated thread. This PR changes that by using `GUIUtil::ObjectInvoke` to run the relevant code in that thread. A possible follow-up is to ditch the dedicated thread and use `QThreadPool` or even `QtConcurrent::run` (if we want to enable that). ACKs for top commit: hebasto: ACK03a5fe06bd
, tested on Linux Mint 20.2 (Qt 5.12.8). jarolrod: ACK03a5fe06bd
Tree-SHA512: 8b40300371d4c04efb9913600a06ba4899af0b5f50fdb26ea23ec751df6d3bd52f8bd693a5e8f6a94ebf3790583dc96c6070e6878d247dece62347aa9bd99031
This commit is contained in:
@ -5,6 +5,7 @@
|
|||||||
#include <qt/initexecutor.h>
|
#include <qt/initexecutor.h>
|
||||||
|
|
||||||
#include <interfaces/node.h>
|
#include <interfaces/node.h>
|
||||||
|
#include <qt/guiutil.h>
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
#include <util/threadnames.h>
|
#include <util/threadnames.h>
|
||||||
|
|
||||||
@ -18,7 +19,7 @@
|
|||||||
InitExecutor::InitExecutor(interfaces::Node& node)
|
InitExecutor::InitExecutor(interfaces::Node& node)
|
||||||
: QObject(), m_node(node)
|
: QObject(), m_node(node)
|
||||||
{
|
{
|
||||||
this->moveToThread(&m_thread);
|
m_context.moveToThread(&m_thread);
|
||||||
m_thread.start();
|
m_thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,9 +39,10 @@ void InitExecutor::handleRunawayException(const std::exception* e)
|
|||||||
|
|
||||||
void InitExecutor::initialize()
|
void InitExecutor::initialize()
|
||||||
{
|
{
|
||||||
|
GUIUtil::ObjectInvoke(&m_context, [this] {
|
||||||
try {
|
try {
|
||||||
util::ThreadRename("qt-init");
|
util::ThreadRename("qt-init");
|
||||||
qDebug() << __func__ << ": Running initialization in thread";
|
qDebug() << "Running initialization in thread";
|
||||||
interfaces::BlockAndHeaderTipInfo tip_info;
|
interfaces::BlockAndHeaderTipInfo tip_info;
|
||||||
bool rv = m_node.appInitMain(&tip_info);
|
bool rv = m_node.appInitMain(&tip_info);
|
||||||
Q_EMIT initializeResult(rv, tip_info);
|
Q_EMIT initializeResult(rv, tip_info);
|
||||||
@ -49,18 +51,21 @@ void InitExecutor::initialize()
|
|||||||
} catch (...) {
|
} catch (...) {
|
||||||
handleRunawayException(nullptr);
|
handleRunawayException(nullptr);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitExecutor::shutdown()
|
void InitExecutor::shutdown()
|
||||||
{
|
{
|
||||||
|
GUIUtil::ObjectInvoke(&m_context, [this] {
|
||||||
try {
|
try {
|
||||||
qDebug() << __func__ << ": Running Shutdown in thread";
|
qDebug() << "Running Shutdown in thread";
|
||||||
m_node.appShutdown();
|
m_node.appShutdown();
|
||||||
qDebug() << __func__ << ": Shutdown finished";
|
qDebug() << "Shutdown finished";
|
||||||
Q_EMIT shutdownResult();
|
Q_EMIT shutdownResult();
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
handleRunawayException(&e);
|
handleRunawayException(&e);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
handleRunawayException(nullptr);
|
handleRunawayException(nullptr);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ private:
|
|||||||
void handleRunawayException(const std::exception* e);
|
void handleRunawayException(const std::exception* e);
|
||||||
|
|
||||||
interfaces::Node& m_node;
|
interfaces::Node& m_node;
|
||||||
|
QObject m_context;
|
||||||
QThread m_thread;
|
QThread m_thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include <interfaces/init.h>
|
#include <interfaces/init.h>
|
||||||
#include <interfaces/node.h>
|
#include <interfaces/node.h>
|
||||||
#include <qt/bitcoin.h>
|
#include <qt/bitcoin.h>
|
||||||
#include <qt/initexecutor.h>
|
|
||||||
#include <qt/test/apptests.h>
|
#include <qt/test/apptests.h>
|
||||||
#include <qt/test/rpcnestedtests.h>
|
#include <qt/test/rpcnestedtests.h>
|
||||||
#include <qt/test/uritests.h>
|
#include <qt/test/uritests.h>
|
||||||
|
Reference in New Issue
Block a user