Skip to content

Commit

Permalink
qt: Replace QMetaObject::invokeMethod with atomic operations
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Nov 7, 2020
1 parent 867dbeb commit 6501bb3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ TransactionTableModel::TransactionTableModel(const PlatformStyle *_platformStyle
QAbstractTableModel(parent),
walletModel(parent),
priv(new TransactionTablePriv(this)),
fProcessingQueuedTransactions(false),
platformStyle(_platformStyle)
{
columns << QString() << QString() << tr("Date") << tr("Type") << tr("Label") << BitcoinUnits::getAmountColumnTitle(walletModel->getOptionsModel()->getDisplayUnit());
Expand Down Expand Up @@ -726,14 +725,12 @@ static void ShowProgress(TransactionTableModel *ttm, const std::string &title, i
{
fQueueNotifications = false;
if (vQueueNotifications.size() > 10) { // prevent balloon spam, show maximum 10 balloons
bool invoked = QMetaObject::invokeMethod(ttm, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, true));
assert(invoked);
ttm->setProcessingQueuedTransactions(true);
}
for (unsigned int i = 0; i < vQueueNotifications.size(); ++i)
{
if (vQueueNotifications.size() - i <= 10) {
bool invoked = QMetaObject::invokeMethod(ttm, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, false));
assert(invoked);
ttm->setProcessingQueuedTransactions(false);
}

vQueueNotifications[i].invoke(ttm);
Expand Down
8 changes: 4 additions & 4 deletions src/qt/transactiontablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QAbstractTableModel>
#include <QStringList>

#include <atomic>
#include <memory>

namespace interfaces {
Expand Down Expand Up @@ -81,15 +82,16 @@ class TransactionTableModel : public QAbstractTableModel
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const override;
bool processingQueuedTransactions() const { return fProcessingQueuedTransactions; }
bool processingQueuedTransactions() const { return m_processing_queued_transactions.load(); }
void setProcessingQueuedTransactions(bool value) { m_processing_queued_transactions.store(value); }

private:
WalletModel *walletModel;
std::unique_ptr<interfaces::Handler> m_handler_transaction_changed;
std::unique_ptr<interfaces::Handler> m_handler_show_progress;
QStringList columns;
TransactionTablePriv *priv;
bool fProcessingQueuedTransactions;
std::atomic<bool> m_processing_queued_transactions{false};
const PlatformStyle *platformStyle;

void subscribeToCoreSignals();
Expand All @@ -114,8 +116,6 @@ public Q_SLOTS:
void updateDisplayUnit();
/** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
void updateAmountColumnTitle();
/* Needed to update fProcessingQueuedTransactions through a QueuedConnection */
void setProcessingQueuedTransactions(bool value) { fProcessingQueuedTransactions = value; }

friend class TransactionTablePriv;
};
Expand Down

0 comments on commit 6501bb3

Please sign in to comment.