From 2e8ac064806d3cac06363f0dfa542d2e08cefb39 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 5 Oct 2014 15:21:59 +0200 Subject: [PATCH] Guards for View. Improved logging. --- alethzero/DownloadView.cpp | 2 +- libethereum/DownloadMan.h | 9 +++++++-- libethereum/EthereumPeer.cpp | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/alethzero/DownloadView.cpp b/alethzero/DownloadView.cpp index 657727a6a..56dd9c3d2 100644 --- a/alethzero/DownloadView.cpp +++ b/alethzero/DownloadView.cpp @@ -51,7 +51,7 @@ void DownloadView::paintEvent(QPaintEvent*) QSizeF area(n, n); QPointF pos(0, 0); - auto const& bg = m_man->blocksGot(); + auto bg = m_man->blocksGot(); for (unsigned i = bg.all().first, ei = bg.all().second; i < ei; ++i) { diff --git a/libethereum/DownloadMan.h b/libethereum/DownloadMan.h index bf4a7db7f..3bd401d8e 100644 --- a/libethereum/DownloadMan.h +++ b/libethereum/DownloadMan.h @@ -94,6 +94,7 @@ public: for (auto i: m_subs) i->resetFetch(); } + WriteGuard l(m_lock); m_chain.clear(); m_chain.reserve(_chain.size()); for (auto i = _chain.rbegin(); i != _chain.rend(); ++i) @@ -108,12 +109,14 @@ public: for (auto i: m_subs) i->resetFetch(); } + WriteGuard l(m_lock); m_chain.clear(); m_blocksGot.reset(); } RangeMask taken(bool _desperate = false) const { + ReadGuard l(m_lock); auto ret = m_blocksGot; if (!_desperate) { @@ -126,15 +129,17 @@ public: bool isComplete() const { + ReadGuard l(m_lock); return m_blocksGot.full(); } - h256s chain() const { return m_chain; } + h256s chain() const { ReadGuard l(m_lock); return m_chain; } void foreachSub(std::function const& _f) const { ReadGuard l(x_subs); for(auto i: m_subs) _f(*i); } unsigned subCount() const { ReadGuard l(x_subs); return m_subs.size(); } - RangeMask blocksGot() const { return m_blocksGot; } + RangeMask blocksGot() const { ReadGuard l(m_lock); return m_blocksGot; } private: + mutable SharedMutex m_lock; h256s m_chain; RangeMask m_blocksGot; diff --git a/libethereum/EthereumPeer.cpp b/libethereum/EthereumPeer.cpp index d7d69187d..b45abfbff 100644 --- a/libethereum/EthereumPeer.cpp +++ b/libethereum/EthereumPeer.cpp @@ -115,7 +115,7 @@ void EthereumPeer::tryGrabbingHashChain() void EthereumPeer::giveUpOnFetch() { - clogS(NetNote) << "GIVE UP FETCH"; + clogS(NetNote) << "Finishing fetch..."; // a bit overkill given that the other nodes may yet have the needed blocks, but better to be safe than sorry. if (m_grabbing == Grabbing::Chain || m_grabbing == Grabbing::ChainHelper)