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

Commit e8b7b89

Browse files
committed
Add fix for spurious condition variable wakeup.
Fix typo in packet error encoding.
1 parent 33b4af6 commit e8b7b89

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/common/ble_common.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ uint32_t encode_decode(adapter_t *adapter, encode_function_t encode_function, de
6060

6161
if (_adapter->isInternalError(err_code))
6262
{
63-
error_message << "Not able to decode packet received from target. Code #" << err_code;
64-
_adapter->statusHandler(PKT_DECODE_ERROR, error_message.str().c_str());
63+
error_message << "Not able to encode packet received from target. Code #" << err_code;
64+
_adapter->statusHandler(PKT_ENCODE_ERROR, error_message.str().c_str());
6565
return NRF_ERROR_INTERNAL;
6666
}
6767

src/common/transport/h5_transport.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,17 @@ uint32_t H5Transport::send(std::vector<uint8_t> &data)
227227
logPacket(true, h5EncodedPacket);
228228
nextTransportLayer->send(lastPacket);
229229

230+
const uint8_t seqNumBefore = seqNum;
231+
230232
auto status = ackWaitCondition.wait_for(ackGuard, std::chrono::milliseconds(retransmissionInterval));
231233

232-
if (status == std::cv_status::no_timeout)
234+
// Checking for timeout. Also checking against spurios wakeup by making sure the sequence
235+
// number has actually increased. If the sequence number has not increased, we have not
236+
// received an ACK packet, and should not exit the loop (unless timeout).
237+
// Ref. spurious wakeup:
238+
// http://en.cppreference.com/w/cpp/thread/condition_variable
239+
// https://en.wikipedia.org/wiki/Spurious_wakeup
240+
if (status == std::cv_status::no_timeout && seqNum != seqNumBefore)
233241
{
234242
lastPacket.clear();
235243
return NRF_SUCCESS;

0 commit comments

Comments
 (0)