1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-06 03:43:49 +01:00
This commit is contained in:
J. Nick Koston
2025-06-16 15:09:49 +02:00
parent 58a697bed1
commit 6a756ab3b6
3 changed files with 11 additions and 10 deletions

View File

@@ -348,7 +348,7 @@ void ESP32BLE::loop() {
break;
}
// Return the event to the pool
this->ble_event_pool_.deallocate(ble_event);
this->ble_event_pool_.release(ble_event);
ble_event = this->ble_events_.pop();
}
if (this->advertising_ != nullptr) {
@@ -411,7 +411,7 @@ template<typename... Args> void enqueue_ble_event(Args... args) {
// This should not happen in SPSC queue with single producer
ESP_LOGE(TAG, "BLE queue push failed unexpectedly");
// Return to pool
global_ble->ble_event_pool_.deallocate(event);
global_ble->ble_event_pool_.release(event);
}
}

View File

@@ -174,7 +174,7 @@ class BLEEvent {
this->event_.gap.gap_event = e;
if (p == nullptr) {
return;
return; // Invalid event, but we can't log in header file
}
// Copy data based on event type
@@ -216,10 +216,12 @@ class BLEEvent {
if (p == nullptr) {
this->event_.gattc.gattc_param = nullptr;
this->event_.gattc.data = nullptr;
return;
return; // Invalid event, but we can't log in header file
}
// Heap-allocate param
// 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);
// Copy data for events that need it
@@ -247,10 +249,12 @@ class BLEEvent {
if (p == nullptr) {
this->event_.gatts.gatts_param = nullptr;
this->event_.gatts.data = nullptr;
return;
return; // Invalid event, but we can't log in header file
}
// Heap-allocate param
// 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);
// Copy data for events that need it

View File

@@ -55,16 +55,13 @@ template<uint8_t SIZE> class BLEEventPool {
return event;
}
// Return an event to the pool
void deallocate(BLEEvent *event) {
// Return an event to the pool for reuse
void release(BLEEvent *event) {
if (event == nullptr) {
return;
}
// Events are reused - the load methods handle cleanup
// Just return to free list
this->free_list_.push(event);
// Push cannot fail: pool size = queue size, and we never exceed pool size
}
// Get total number of events created (high water mark)