aboutsummaryrefslogtreecommitdiff
path: root/src/qt/clientmodel.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2017-04-20 13:36:16 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2017-04-20 13:41:07 +0200
commit987a6c09562e1e1e9d6623b999ae9de268490e4b (patch)
treeb40427fee1f71b570e26439dc649d3d47ea44f20 /src/qt/clientmodel.cpp
parenta987def4f629f079d1c87c6c805323b28450f8ed (diff)
parent4082fb0003ca1992c34e9f4c75fba9db281f5fc0 (diff)
downloadbitcoin-987a6c09562e1e1e9d6623b999ae9de268490e4b.tar.xz
Merge #10231: [Qt] Reduce a significant cs_main lock freeze
4082fb0 Add missing <atomic> header in clientmodel.h (Jonas Schnelli) 928d4a9 Set both time/height header caches at the same time (Jonas Schnelli) 610a917 Declare headers height/time cache mutable, re-set the methods const (Jonas Schnelli) cf92bce Update the remaining blocks left in modaloverlay at init. (Jonas Schnelli) 7148f5e Reduce cs_main locks during modal overlay by adding an atomic cache (Jonas Schnelli) Tree-SHA512: a92ca22f90b8b2a5e8eb94fdce531ef44542e21a8dbbb0693f7723d7018592cb68de687a2a0aac91d31cbf019793f8e922550656d2b130ed3d854d60630341db
Diffstat (limited to 'src/qt/clientmodel.cpp')
-rw-r--r--src/qt/clientmodel.cpp33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp
index bb10e49422..20d4687971 100644
--- a/src/qt/clientmodel.cpp
+++ b/src/qt/clientmodel.cpp
@@ -36,6 +36,8 @@ ClientModel::ClientModel(OptionsModel *_optionsModel, QObject *parent) :
banTableModel(0),
pollTimer(0)
{
+ cachedBestHeaderHeight = -1;
+ cachedBestHeaderTime = -1;
peerTableModel = new PeerTableModel(this);
banTableModel = new BanTableModel(this);
pollTimer = new QTimer(this);
@@ -74,18 +76,28 @@ int ClientModel::getNumBlocks() const
int ClientModel::getHeaderTipHeight() const
{
- LOCK(cs_main);
- if (!pindexBestHeader)
- return 0;
- return pindexBestHeader->nHeight;
+ if (cachedBestHeaderHeight == -1) {
+ // make sure we initially populate the cache via a cs_main lock
+ // otherwise we need to wait for a tip update
+ LOCK(cs_main);
+ if (pindexBestHeader) {
+ cachedBestHeaderHeight = pindexBestHeader->nHeight;
+ cachedBestHeaderTime = pindexBestHeader->GetBlockTime();
+ }
+ }
+ return cachedBestHeaderHeight;
}
int64_t ClientModel::getHeaderTipTime() const
{
- LOCK(cs_main);
- if (!pindexBestHeader)
- return 0;
- return pindexBestHeader->GetBlockTime();
+ if (cachedBestHeaderTime == -1) {
+ LOCK(cs_main);
+ if (pindexBestHeader) {
+ cachedBestHeaderHeight = pindexBestHeader->nHeight;
+ cachedBestHeaderTime = pindexBestHeader->GetBlockTime();
+ }
+ }
+ return cachedBestHeaderTime;
}
quint64 ClientModel::getTotalBytesRecv() const
@@ -283,6 +295,11 @@ static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CB
int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification;
+ if (fHeader) {
+ // cache best headers time and height to reduce future cs_main locks
+ clientmodel->cachedBestHeaderHeight = pIndex->nHeight;
+ clientmodel->cachedBestHeaderTime = pIndex->GetBlockTime();
+ }
// if we are in-sync, update the UI regardless of last update time
if (!initialSync || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) {
//pass a async signal to the UI thread