aboutsummaryrefslogtreecommitdiff
path: root/src/qt
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-04-23 08:40:48 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-04-23 09:07:18 +0200
commit41106a50d2be9358ab19e75c1d6d075a773525b7 (patch)
treecdda729dd8d02fc4052531ee902f51a21b8a2b12 /src/qt
parented671005654136b728768a423c8ac7f4e1ce637f (diff)
downloadbitcoin-41106a50d2be9358ab19e75c1d6d075a773525b7.tar.xz
qt: get required locks upfront in polling functions
This avoids the GUI from getting stuck on periodical polls if the core is holding the locks for a longer time - for example, during a wallet rescan.
Diffstat (limited to 'src/qt')
-rw-r--r--src/qt/clientmodel.cpp6
-rw-r--r--src/qt/transactiontablemodel.cpp21
-rw-r--r--src/qt/walletmodel.cpp25
3 files changed, 34 insertions, 18 deletions
diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp
index 287296644c..3c0564c208 100644
--- a/src/qt/clientmodel.cpp
+++ b/src/qt/clientmodel.cpp
@@ -92,6 +92,12 @@ double ClientModel::getVerificationProgress() const
void ClientModel::updateTimer()
{
+ // Get required lock upfront. This avoids the GUI from getting stuck on
+ // periodical polls if the core is holding the locks for a longer time -
+ // for example, during a wallet rescan.
+ TRY_LOCK(cs_main, lockMain);
+ if(!lockMain)
+ return;
// Some quantities (such as number of blocks) change so fast that we don't want to be notified for each change.
// Periodically check and update with a timer.
int newNumBlocks = getNumBlocks();
diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp
index aaecf88c25..df412650d8 100644
--- a/src/qt/transactiontablemodel.cpp
+++ b/src/qt/transactiontablemodel.cpp
@@ -24,7 +24,6 @@
#include <QDebug>
#include <QIcon>
#include <QList>
-#include <QTimer>
// Amount column is right-aligned it contains numbers
static int column_alignments[] = {
@@ -187,17 +186,25 @@ public:
{
TransactionRecord *rec = &cachedWallet[idx];
+ // Get required locks upfront. This avoids the GUI from getting
+ // stuck if the core is holding the locks for a longer time - for
+ // example, during a wallet rescan.
+ //
// If a status update is needed (blocks came in since last check),
// update the status of this transaction from the wallet. Otherwise,
// simply re-use the cached status.
- LOCK2(cs_main, wallet->cs_wallet);
- if(rec->statusUpdateNeeded())
+ TRY_LOCK(cs_main, lockMain);
+ if(lockMain)
{
- std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash);
-
- if(mi != wallet->mapWallet.end())
+ TRY_LOCK(wallet->cs_wallet, lockWallet);
+ if(lockWallet && rec->statusUpdateNeeded())
{
- rec->updateStatus(mi->second);
+ std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash);
+
+ if(mi != wallet->mapWallet.end())
+ {
+ rec->updateStatus(mi->second);
+ }
}
}
return rec;
diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp
index 61f26107af..37d82ec063 100644
--- a/src/qt/walletmodel.cpp
+++ b/src/qt/walletmodel.cpp
@@ -98,18 +98,21 @@ void WalletModel::updateStatus()
void WalletModel::pollBalanceChanged()
{
- bool heightChanged = false;
- {
- LOCK(cs_main);
- if(chainActive.Height() != cachedNumBlocks)
- {
- // Balance and number of transactions might have changed
- cachedNumBlocks = chainActive.Height();
- heightChanged = true;
- }
- }
- if(heightChanged)
+ // Get required locks upfront. This avoids the GUI from getting stuck on
+ // periodical polls if the core is holding the locks for a longer time -
+ // for example, during a wallet rescan.
+ TRY_LOCK(cs_main, lockMain);
+ if(!lockMain)
+ return;
+ TRY_LOCK(wallet->cs_wallet, lockWallet);
+ if(!lockWallet)
+ return;
+
+ if(chainActive.Height() != cachedNumBlocks)
{
+ // Balance and number of transactions might have changed
+ cachedNumBlocks = chainActive.Height();
+
checkBalanceChanged();
if(transactionTableModel)
transactionTableModel->updateConfirmations();