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.
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user