From 6e739ac4534f5117307366a499144d4b79953e62 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 16 Jun 2025 15:23:04 +0200 Subject: [PATCH] ble pool --- esphome/components/esp32_ble/ble_event.h | 4 ++-- esphome/components/esp32_ble/queue.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/esphome/components/esp32_ble/ble_event.h b/esphome/components/esp32_ble/ble_event.h index faccb034c6..0e75bb7dd7 100644 --- a/esphome/components/esp32_ble/ble_event.h +++ b/esphome/components/esp32_ble/ble_event.h @@ -219,7 +219,7 @@ class BLEEvent { return; // Invalid event, but we can't log in header file } - // Heap-allocate param + // Heap-allocate param and data // Heap allocation is used because GATTC/GATTS events are rare (<1% of events) // while GAP events (99%) are stored inline to minimize memory usage this->event_.gattc.gattc_param = new esp_ble_gattc_cb_param_t(*p); @@ -252,7 +252,7 @@ class BLEEvent { return; // Invalid event, but we can't log in header file } - // Heap-allocate param + // Heap-allocate param and data // Heap allocation is used because GATTC/GATTS events are rare (<1% of events) // while GAP events (99%) are stored inline to minimize memory usage this->event_.gatts.gatts_param = new esp_ble_gatts_cb_param_t(*p); diff --git a/esphome/components/esp32_ble/queue.h b/esphome/components/esp32_ble/queue.h index b329f219dc..0f8eb23425 100644 --- a/esphome/components/esp32_ble/queue.h +++ b/esphome/components/esp32_ble/queue.h @@ -71,8 +71,11 @@ template class LockFreeQueue { protected: T *buffer_[SIZE]; + // Atomic: written by consumer (pop), read by producer (push) to check if full std::atomic head_; + // Atomic: written by producer (push), read by consumer (pop) to check if empty std::atomic tail_; + // Atomic: written by producer (push/increment), read+reset by consumer (get_and_reset) std::atomic dropped_count_; // Keep this larger for accumulated counts };