From 41106a50d2be9358ab19e75c1d6d075a773525b7 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 23 Apr 2014 08:40:48 +0200 Subject: 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. --- src/qt/transactiontablemodel.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/qt/transactiontablemodel.cpp') 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 #include #include -#include // 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::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::iterator mi = wallet->mapWallet.find(rec->hash); + + if(mi != wallet->mapWallet.end()) + { + rec->updateStatus(mi->second); + } } } return rec; -- cgit v1.2.3