Fix countBefore sentinel regression from millis wraparound fix

PR #1795 changed PacketQueue::countBefore() to use signed 2's complement
arithmetic for millis wraparound safety. However, this broke the
0xFFFFFFFF sentinel pattern used by callers to mean "count all packets
regardless of schedule".

With the signed comparison, countBefore(0xFFFFFFFF) always returns 0,
causing hasPendingWork() to report false and repeaters to sleep with
packets still queued. Stats reporting also shows queue_len as 0.

Add an early-return for the sentinel value before the loop, and document
the sentinel convention on the virtual interface and implementation.
This commit is contained in:
Daniel Novak
2026-02-28 16:22:58 +01:00
parent 06ab9f7f6b
commit c436bd42c5
3 changed files with 3 additions and 2 deletions
+1
View File
@@ -9,6 +9,7 @@ PacketQueue::PacketQueue(int max_entries) {
}
int PacketQueue::countBefore(uint32_t now) const {
if (now == 0xFFFFFFFF) return _num; // sentinel: count all entries regardless of schedule
int n = 0;
for (int j = 0; j < _num; j++) {
if ((int32_t)(_schedule_table[j] - now) > 0) continue; // scheduled for future... ignore for now