From 2a26a0188c66e39652f6a0c33454c3206ca666aa Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 16 Jun 2025 15:29:37 +0200 Subject: [PATCH] ble pool --- esphome/components/esp32_ble/ble.cpp | 2 +- esphome/components/esp32_ble/queue.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/esphome/components/esp32_ble/ble.cpp b/esphome/components/esp32_ble/ble.cpp index 72ffc6c381..fc26bc8bba 100644 --- a/esphome/components/esp32_ble/ble.cpp +++ b/esphome/components/esp32_ble/ble.cpp @@ -356,7 +356,7 @@ void ESP32BLE::loop() { } // Log dropped events periodically - uint32_t dropped = this->ble_events_.get_and_reset_dropped_count(); + uint16_t dropped = this->ble_events_.get_and_reset_dropped_count(); if (dropped > 0) { ESP_LOGW(TAG, "Dropped %u BLE events due to buffer overflow", dropped); } diff --git a/esphome/components/esp32_ble/queue.h b/esphome/components/esp32_ble/queue.h index ee6bce72d6..75bf1eef25 100644 --- a/esphome/components/esp32_ble/queue.h +++ b/esphome/components/esp32_ble/queue.h @@ -58,7 +58,7 @@ template class LockFreeQueue { return (tail - head + SIZE) % SIZE; } - uint32_t get_and_reset_dropped_count() { return dropped_count_.exchange(0, std::memory_order_relaxed); } + uint16_t get_and_reset_dropped_count() { return dropped_count_.exchange(0, std::memory_order_relaxed); } void increment_dropped_count() { dropped_count_.fetch_add(1, std::memory_order_relaxed); } @@ -72,7 +72,7 @@ template class LockFreeQueue { protected: T *buffer_[SIZE]; // Atomic: written by producer (push/increment), read+reset by consumer (get_and_reset) - std::atomic dropped_count_; // Keep this larger for accumulated counts + std::atomic dropped_count_; // 65535 max - more than enough for drop tracking // 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