From 3c208050b0dbf9b852aa7739447dcfdf75779ee9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 11 Jun 2025 11:47:34 -0500 Subject: [PATCH] comments --- esphome/components/esp32_ble/queue.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/esphome/components/esp32_ble/queue.h b/esphome/components/esp32_ble/queue.h index afa9a9b668..49b0ec5480 100644 --- a/esphome/components/esp32_ble/queue.h +++ b/esphome/components/esp32_ble/queue.h @@ -46,7 +46,13 @@ template 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: