1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-22 04:04:16 +00:00

unlock mutex for good after wait

This commit is contained in:
orignal 2022-12-30 22:12:49 -05:00
parent cb139226df
commit 3e3e2c41bd

View File

@ -481,7 +481,6 @@ namespace stream
volatile bool done = false;
std::condition_variable newDataReceived;
std::mutex newDataReceivedMutex;
std::unique_lock<std::mutex> 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<std::mutex> 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<std::mutex> 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