From 345416e7d7010223f48bf0d9d3c29bf444bf1b91 Mon Sep 17 00:00:00 2001 From: subtly Date: Sat, 6 Dec 2014 23:01:55 +0100 Subject: [PATCH] thread-safety fix --- libwhisper/WhisperPeer.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libwhisper/WhisperPeer.cpp b/libwhisper/WhisperPeer.cpp index 0951a3726..359d31c4e 100644 --- a/libwhisper/WhisperPeer.cpp +++ b/libwhisper/WhisperPeer.cpp @@ -82,21 +82,21 @@ bool WhisperPeer::interpret(unsigned _id, RLP const& _r) void WhisperPeer::sendMessages() { - if (m_unseen.size()) + RLPStream amalg; + unsigned msgCount = 0; { - RLPStream amalg; - unsigned msgCount; + Guard l(x_unseen); + msgCount = m_unseen.size(); + while (m_unseen.size()) { - Guard l(x_unseen); - msgCount = m_unseen.size(); - while (m_unseen.size()) - { - auto p = *m_unseen.begin(); - m_unseen.erase(m_unseen.begin()); - host()->streamMessage(p.second, amalg); - } + auto p = *m_unseen.begin(); + m_unseen.erase(m_unseen.begin()); + host()->streamMessage(p.second, amalg); } - + } + + if (msgCount) + { RLPStream s; prep(s, MessagesPacket, msgCount).appendRaw(amalg.out(), msgCount); sealAndSend(s);