TransactionHistory: guard tx info list against concurrent access

This commit is contained in:
xiphon 2019-12-04 10:29:27 +00:00
parent d5f4d5d93f
commit 9d5eb002ae
2 changed files with 45 additions and 31 deletions

View file

@ -32,10 +32,13 @@
#include <QFile>
#include <QDebug>
#include <QReadLocker>
#include <QWriteLocker>
TransactionInfo *TransactionHistory::transaction(int index)
{
QReadLocker locker(&m_tinfoLock);
if (index < 0 || index >= m_tinfo.size()) {
qCritical("%s: no transaction info for index %d", __FUNCTION__, index);
@ -53,13 +56,18 @@ TransactionInfo *TransactionHistory::transaction(int index)
QList<TransactionInfo *> TransactionHistory::getAll(quint32 accountIndex) const
{
// XXX this invalidates previously saved history that might be used by model
QDateTime firstDateTime = QDateTime(QDate(2014, 4, 18)); // the genesis block
QDateTime lastDateTime = QDateTime::currentDateTime().addDays(1); // tomorrow (guard against jitter and timezones)
emit refreshStarted();
{
QWriteLocker locker(&m_tinfoLock);
// XXX this invalidates previously saved history that might be used by model
qDeleteAll(m_tinfo);
m_tinfo.clear();
QDateTime firstDateTime = QDateTime(QDate(2014, 4, 18)); // the genesis block
QDateTime lastDateTime = QDateTime::currentDateTime().addDays(1); // tomorrow (guard against jitter and timezones)
quint64 lastTxHeight = 0;
m_locked = false;
m_minutesToUnlock = 0;
@ -88,6 +96,8 @@ QList<TransactionInfo *> TransactionHistory::getAll(quint32 accountIndex) const
}
}
}
emit refreshFinished();
if (m_firstDateTime != firstDateTime) {
@ -112,6 +122,8 @@ void TransactionHistory::refresh(quint32 accountIndex)
quint64 TransactionHistory::count() const
{
QReadLocker locker(&m_tinfoLock);
return m_tinfo.count();
}

View file

@ -31,6 +31,7 @@
#include <QObject>
#include <QList>
#include <QReadWriteLock>
#include <QDateTime>
namespace Monero {
@ -76,6 +77,7 @@ private:
friend class Wallet;
Monero::TransactionHistory * m_pimpl;
mutable QList<TransactionInfo*> m_tinfo;
mutable QReadWriteLock m_tinfoLock;
mutable QDateTime m_firstDateTime;
mutable QDateTime m_lastDateTime;
mutable int m_minutesToUnlock;