diff options
| author | Wladimir J. van der Laan <[email protected]> | 2014-04-23 08:40:48 +0200 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2014-04-23 09:07:18 +0200 |
| commit | 41106a50d2be9358ab19e75c1d6d075a773525b7 (patch) | |
| tree | cdda729dd8d02fc4052531ee902f51a21b8a2b12 /src/qt/walletmodel.cpp | |
| parent | Add required locks in tests (diff) | |
| download | discoin-41106a50d2be9358ab19e75c1d6d075a773525b7.tar.xz discoin-41106a50d2be9358ab19e75c1d6d075a773525b7.zip | |
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/walletmodel.cpp')
| -rw-r--r-- | src/qt/walletmodel.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 61f26107a..37d82ec06 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(); |