Unverified Commit 7fe2c02f authored by Bjørn Inge Hanssen's avatar Bjørn Inge Hanssen Committed by GitHub
Browse files

Merge pull request #66 from NordicSemiconductor/fix/NCP1439-retransmission-v3x

Add fix for spurious condition variable wakeup
parents 404ff3ee aa7ec8a1
......@@ -60,8 +60,8 @@ uint32_t encode_decode(adapter_t *adapter, encode_function_t encode_function, de
if (_adapter->isInternalError(err_code))
error_message << "Not able to decode packet received from target. Code #" << err_code;
_adapter->statusHandler(PKT_DECODE_ERROR, error_message.str().c_str());
error_message << "Not able to encode packet. Code #" << err_code;
_adapter->statusHandler(PKT_ENCODE_ERROR, error_message.str().c_str());
......@@ -227,9 +227,17 @@ uint32_t H5Transport::send(std::vector<uint8_t> &data)
logPacket(true, h5EncodedPacket);
const uint8_t seqNumBefore = seqNum;
auto status = ackWaitCondition.wait_for(ackGuard, std::chrono::milliseconds(retransmissionInterval));
if (status == std::cv_status::no_timeout)
// Checking for timeout. Also checking against spurios wakeup by making sure the sequence
// number has actually increased. If the sequence number has not increased, we have not
// received an ACK packet, and should not exit the loop (unless timeout).
// Ref. spurious wakeup:
// http://en.cppreference.com/w/cpp/thread/condition_variable
// https://en.wikipedia.org/wiki/Spurious_wakeup
if (status == std::cv_status::no_timeout && seqNum != seqNumBefore)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment