mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
merge bitcoin#17135: Make polling in ClientModel asynchronous
This commit is contained in:
parent
e13d93ec78
commit
8278e8ab0f
@ -29,6 +29,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
|
||||
static int64_t nLastHeaderTipUpdateNotification = 0;
|
||||
@ -40,23 +41,37 @@ ClientModel::ClientModel(interfaces::Node& node, OptionsModel *_optionsModel, QO
|
||||
optionsModel(_optionsModel),
|
||||
peerTableModel(nullptr),
|
||||
banTableModel(nullptr),
|
||||
pollTimer(nullptr)
|
||||
m_thread(new QThread(this))
|
||||
{
|
||||
cachedBestHeaderHeight = -1;
|
||||
cachedBestHeaderTime = -1;
|
||||
peerTableModel = new PeerTableModel(m_node, this);
|
||||
banTableModel = new BanTableModel(m_node, this);
|
||||
pollTimer = new QTimer(this);
|
||||
connect(pollTimer, &QTimer::timeout, this, &ClientModel::updateTimer);
|
||||
pollTimer->start(MODEL_UPDATE_DELAY);
|
||||
mnListCached = std::make_shared<CDeterministicMNList>();
|
||||
|
||||
QTimer* timer = new QTimer;
|
||||
timer->setInterval(MODEL_UPDATE_DELAY);
|
||||
connect(timer, &QTimer::timeout, [this] {
|
||||
// no locking required at this point
|
||||
// the following calls will acquire the required lock
|
||||
Q_EMIT mempoolSizeChanged(m_node.getMempoolSize(), m_node.getMempoolDynamicUsage());
|
||||
Q_EMIT islockCountChanged(m_node.llmq().getInstantSentLockCount());
|
||||
});
|
||||
connect(m_thread, &QThread::finished, timer, &QObject::deleteLater);
|
||||
connect(m_thread, &QThread::started, [timer] { timer->start(); });
|
||||
// move timer to thread so that polling doesn't disturb main event loop
|
||||
timer->moveToThread(m_thread);
|
||||
m_thread->start();
|
||||
|
||||
subscribeToCoreSignals();
|
||||
}
|
||||
|
||||
ClientModel::~ClientModel()
|
||||
{
|
||||
unsubscribeFromCoreSignals();
|
||||
|
||||
m_thread->quit();
|
||||
m_thread->wait();
|
||||
}
|
||||
|
||||
int ClientModel::getNumConnections(unsigned int flags) const
|
||||
@ -128,14 +143,6 @@ std::vector<const CGovernanceObject*> ClientModel::getAllGovernanceObjects()
|
||||
return m_node.gov().getAllNewerThan(0);
|
||||
}
|
||||
|
||||
void ClientModel::updateTimer()
|
||||
{
|
||||
// no locking required at this point
|
||||
// the following calls will acquire the required lock
|
||||
Q_EMIT mempoolSizeChanged(m_node.getMempoolSize(), m_node.getMempoolDynamicUsage());
|
||||
Q_EMIT islockCountChanged(m_node.llmq().getInstantSentLockCount());
|
||||
}
|
||||
|
||||
void ClientModel::updateNumConnections(int numConnections)
|
||||
{
|
||||
Q_EMIT numConnectionsChanged(numConnections);
|
||||
|
@ -104,7 +104,8 @@ private:
|
||||
PeerTableModel *peerTableModel;
|
||||
BanTableModel *banTableModel;
|
||||
|
||||
QTimer *pollTimer;
|
||||
//! A thread to interact with m_node asynchronously
|
||||
QThread* const m_thread;
|
||||
|
||||
// The cache for mn list is not technically needed because CDeterministicMNManager
|
||||
// caches it internally for recent blocks but it's not enough to get consistent
|
||||
@ -133,7 +134,6 @@ Q_SIGNALS:
|
||||
void showProgress(const QString &title, int nProgress);
|
||||
|
||||
public Q_SLOTS:
|
||||
void updateTimer();
|
||||
void updateNumConnections(int numConnections);
|
||||
void updateNetworkActive(bool networkActive);
|
||||
void updateAlert();
|
||||
|
Loading…
Reference in New Issue
Block a user