Fast path for get_and_reset_dropped_count to avoid critical section

Plain read of aligned uint16_t is safe on ARM. Since drops are rare,
almost every call returns 0 without entering a critical section.
This commit is contained in:
J. Nick Koston
2026-03-31 21:32:26 -10:00
parent bb2991bfda
commit 1e156d46b6
+4
View File
@@ -59,6 +59,10 @@ template<class T, uint8_t SIZE> class FreeRTOSQueue {
}
uint16_t get_and_reset_dropped_count() {
// Fast path: plain read is safe for aligned uint16_t on ARM.
// Drops are rare so almost always returns 0 without entering a critical section.
if (this->dropped_count_ == 0)
return 0;
portENTER_CRITICAL();
uint16_t count = this->dropped_count_;
this->dropped_count_ = 0;