Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace QMetaObject::invokeMethod with atomic operations #127

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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