From 3e3e2c41bd7583bed7b8da46781ee6e6df0fc39b Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 30 Dec 2022 22:12:49 -0500 Subject: [PATCH] unlock mutex for good after wait --- libi2pd/Streaming.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libi2pd/Streaming.cpp b/libi2pd/Streaming.cpp index dda74015..0c584e2f 100644 --- a/libi2pd/Streaming.cpp +++ b/libi2pd/Streaming.cpp @@ -481,7 +481,6 @@ namespace stream volatile bool done = false; std::condition_variable newDataReceived; std::mutex newDataReceivedMutex; - std::unique_lock l(newDataReceivedMutex); AsyncReceive (boost::asio::buffer (buf, len), [&ret, &done, &newDataReceived, &newDataReceivedMutex](const boost::system::error_code& ecode, std::size_t bytes_transferred) { @@ -490,12 +489,15 @@ namespace stream else ret = bytes_transferred; std::unique_lock l(newDataReceivedMutex); - done = true; newDataReceived.notify_all (); + done = true; }, timeout); - if (newDataReceived.wait_for (l, std::chrono::seconds (timeout)) == std::cv_status::timeout) - ret = 0; + if (!done) + { std::unique_lock l(newDataReceivedMutex); + if (!done && newDataReceived.wait_for (l, std::chrono::seconds (timeout)) == std::cv_status::timeout) + ret = 0; + } if (!done) { // make sure that AsycReceive complete