mirror of
https://github.com/esphome/esphome.git
synced 2025-10-05 19:33:47 +01:00
cleanup
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user