From 43f0112456b7f5d56f746f00f1eb3c1cea0616ea Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Mon, 29 Jun 2015 12:38:06 +0200 Subject: [PATCH] Mutex & reference counter --- libwhisper/WhisperHost.cpp | 5 ++++- libwhisper/WhisperPeer.cpp | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libwhisper/WhisperHost.cpp b/libwhisper/WhisperHost.cpp index 1a47a56d1..2d037133c 100644 --- a/libwhisper/WhisperHost.cpp +++ b/libwhisper/WhisperHost.cpp @@ -94,8 +94,11 @@ unsigned WhisperHost::installWatch(shh::Topics const& _t) DEV_GUARDED(m_filterLock) { - if (!m_filters.count(h)) + auto it = m_filters.find(h); + if (m_filters.end() == it) m_filters.insert(make_pair(h, f)); + else + it->second.refCount++; ret = m_watches.size() ? m_watches.rbegin()->first + 1 : 0; m_watches[ret] = ClientWatch(h); diff --git a/libwhisper/WhisperPeer.cpp b/libwhisper/WhisperPeer.cpp index 665364f49..1f48468df 100644 --- a/libwhisper/WhisperPeer.cpp +++ b/libwhisper/WhisperPeer.cpp @@ -58,7 +58,10 @@ bool WhisperPeer::interpret(unsigned _id, RLP const& _r) disable("Invalid protocol version."); for (auto const& m: host()->all()) + { + Guard l(x_unseen); m_unseen.insert(make_pair(0, m.first)); + } if (session()->id() < host()->host()->id()) sendMessages();