Browse Source

Fixed a potential deadlock when peer is released in forEachPeer

cl-refactor
arkpar 10 years ago
parent
commit
2daad53d8c
  1. 20
      libethereum/EthereumHost.cpp
  2. 2
      libethereum/EthereumHost.h

20
libethereum/EthereumHost.cpp

@ -84,7 +84,7 @@ bool EthereumHost::ensureInitialised()
void EthereumHost::reset() void EthereumHost::reset()
{ {
Guard l(x_sync); RecursiveGuard l(x_sync);
if (m_sync) if (m_sync)
m_sync->abortSync(); m_sync->abortSync();
m_sync.reset(); m_sync.reset();
@ -118,7 +118,7 @@ void EthereumHost::doWork()
if (m_syncStart) if (m_syncStart)
{ {
DEV_GUARDED(x_sync) DEV_RECURSIVE_GUARDED(x_sync)
if (!m_sync) if (!m_sync)
{ {
time_t now = std::chrono::system_clock::to_time_t(chrono::system_clock::now()); time_t now = std::chrono::system_clock::to_time_t(chrono::system_clock::now());
@ -288,35 +288,35 @@ BlockChainSync* EthereumHost::sync()
void EthereumHost::onPeerStatus(std::shared_ptr<EthereumPeer> _peer) void EthereumHost::onPeerStatus(std::shared_ptr<EthereumPeer> _peer)
{ {
Guard l(x_sync); RecursiveGuard l(x_sync);
if (sync()) if (sync())
sync()->onPeerStatus(_peer); sync()->onPeerStatus(_peer);
} }
void EthereumHost::onPeerHashes(std::shared_ptr<EthereumPeer> _peer, h256s const& _hashes) void EthereumHost::onPeerHashes(std::shared_ptr<EthereumPeer> _peer, h256s const& _hashes)
{ {
Guard l(x_sync); RecursiveGuard l(x_sync);
if (sync()) if (sync())
sync()->onPeerHashes(_peer, _hashes); sync()->onPeerHashes(_peer, _hashes);
} }
void EthereumHost::onPeerBlocks(std::shared_ptr<EthereumPeer> _peer, RLP const& _r) void EthereumHost::onPeerBlocks(std::shared_ptr<EthereumPeer> _peer, RLP const& _r)
{ {
Guard l(x_sync); RecursiveGuard l(x_sync);
if (sync()) if (sync())
sync()->onPeerBlocks(_peer, _r); sync()->onPeerBlocks(_peer, _r);
} }
void EthereumHost::onPeerNewHashes(std::shared_ptr<EthereumPeer> _peer, h256s const& _hashes) void EthereumHost::onPeerNewHashes(std::shared_ptr<EthereumPeer> _peer, h256s const& _hashes)
{ {
Guard l(x_sync); RecursiveGuard l(x_sync);
if (sync()) if (sync())
sync()->onPeerNewHashes(_peer, _hashes); sync()->onPeerNewHashes(_peer, _hashes);
} }
void EthereumHost::onPeerNewBlock(std::shared_ptr<EthereumPeer> _peer, RLP const& _r) void EthereumHost::onPeerNewBlock(std::shared_ptr<EthereumPeer> _peer, RLP const& _r)
{ {
Guard l(x_sync); RecursiveGuard l(x_sync);
if (sync()) if (sync())
sync()->onPeerNewBlock(_peer, _r); sync()->onPeerNewBlock(_peer, _r);
} }
@ -335,7 +335,7 @@ void EthereumHost::onPeerTransactions(std::shared_ptr<EthereumPeer> _peer, RLP c
void EthereumHost::onPeerAborting() void EthereumHost::onPeerAborting()
{ {
Guard l(x_sync); RecursiveGuard l(x_sync);
try try
{ {
if (m_sync) if (m_sync)
@ -349,7 +349,7 @@ void EthereumHost::onPeerAborting()
bool EthereumHost::isSyncing() const bool EthereumHost::isSyncing() const
{ {
Guard l(x_sync); RecursiveGuard l(x_sync);
if (!m_sync) if (!m_sync)
return false; return false;
return m_sync->isSyncing(); return m_sync->isSyncing();
@ -357,7 +357,7 @@ bool EthereumHost::isSyncing() const
SyncStatus EthereumHost::status() const SyncStatus EthereumHost::status() const
{ {
Guard l(x_sync); RecursiveGuard l(x_sync);
if (!m_sync) if (!m_sync)
return SyncStatus(); return SyncStatus();
return m_sync->status(); return m_sync->status();

2
libethereum/EthereumHost.h

@ -134,7 +134,7 @@ private:
bool m_newTransactions = false; bool m_newTransactions = false;
bool m_newBlocks = false; bool m_newBlocks = false;
mutable Mutex x_sync; mutable RecursiveMutex x_sync;
mutable Mutex x_transactions; mutable Mutex x_transactions;
DownloadMan m_man; DownloadMan m_man;
std::unique_ptr<BlockChainSync> m_sync; std::unique_ptr<BlockChainSync> m_sync;

Loading…
Cancel
Save