Skip to content

Commit c436bd4

Browse files
committed
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.
1 parent 06ab9f7 commit c436bd4

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

src/Dispatcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class PacketManager {
8989

9090
virtual void queueOutbound(Packet* packet, uint8_t priority, uint32_t scheduled_for) = 0;
9191
virtual Packet* getNextOutbound(uint32_t now) = 0; // by priority
92-
virtual int getOutboundCount(uint32_t now) const = 0;
92+
virtual int getOutboundCount(uint32_t now) const = 0; // pass now=0xFFFFFFFF to count all
9393
virtual int getFreeCount() const = 0;
9494
virtual Packet* getOutboundByIdx(int i) = 0;
9595
virtual Packet* removeOutboundByIdx(int i) = 0;

src/helpers/StaticPoolPacketManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ PacketQueue::PacketQueue(int max_entries) {
99
}
1010

1111
int PacketQueue::countBefore(uint32_t now) const {
12+
if (now == 0xFFFFFFFF) return _num; // sentinel: count all entries regardless of schedule
1213
int n = 0;
1314
for (int j = 0; j < _num; j++) {
1415
if ((int32_t)(_schedule_table[j] - now) > 0) continue; // scheduled for future... ignore for now

src/helpers/StaticPoolPacketManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PacketQueue {
1313
mesh::Packet* get(uint32_t now);
1414
bool add(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for);
1515
int count() const { return _num; }
16-
int countBefore(uint32_t now) const;
16+
int countBefore(uint32_t now) const; // pass now=0xFFFFFFFF to count all
1717
mesh::Packet* itemAt(int i) const { return _table[i]; }
1818
mesh::Packet* removeByIdx(int i);
1919
};

0 commit comments

Comments
 (0)