Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #65 from NordicSemiconductor/fix/NCP1439-retransmi…
Browse files Browse the repository at this point in the history
…ssion

Add fix for spurious condition variable wakeup.
  • Loading branch information
bihanssen authored Jan 16, 2018
2 parents 33b4af6 + e8b7b89 commit 62b3be9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/common/ble_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 received from target. Code #" << err_code;
_adapter->statusHandler(PKT_ENCODE_ERROR, error_message.str().c_str());
return NRF_ERROR_INTERNAL;
}

Expand Down
10 changes: 9 additions & 1 deletion src/common/transport/h5_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,17 @@ uint32_t H5Transport::send(std::vector<uint8_t> &data)
logPacket(true, h5EncodedPacket);
nextTransportLayer->send(lastPacket);

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)
{
lastPacket.clear();
return NRF_SUCCESS;
Expand Down

0 comments on commit 62b3be9

Please sign in to comment.