1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-15 17:52:19 +01:00
This commit is contained in:
J. Nick Koston
2025-06-11 11:47:34 -05:00
parent bbc7c9fb37
commit 3c208050b0

View File

@@ -46,7 +46,13 @@ template<class T> class Queue {
}
size_t size() const {
return q_.size(); // Atomic read, no lock needed
// Lock-free size check. While std::queue::size() is not thread-safe, we intentionally
// avoid locking here to prevent blocking the BLE callback thread. The size is only
// used to decide whether to drop incoming events when the queue is near capacity.
// With a queue limit of 40-64 events and normal processing, dropping events should
// be extremely rare. When it does approach capacity, being off by 1-2 events is
// acceptable to avoid blocking the BLE stack's time-sensitive callbacks.
return q_.size();
}
protected: