mirror of
https://github.com/esphome/esphome.git
synced 2025-10-06 03:43:49 +01:00
cleanup
This commit is contained in:
@@ -348,7 +348,7 @@ void ESP32BLE::loop() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Return the event to the pool
|
// 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();
|
ble_event = this->ble_events_.pop();
|
||||||
}
|
}
|
||||||
if (this->advertising_ != nullptr) {
|
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
|
// This should not happen in SPSC queue with single producer
|
||||||
ESP_LOGE(TAG, "BLE queue push failed unexpectedly");
|
ESP_LOGE(TAG, "BLE queue push failed unexpectedly");
|
||||||
// Return to pool
|
// 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;
|
this->event_.gap.gap_event = e;
|
||||||
|
|
||||||
if (p == nullptr) {
|
if (p == nullptr) {
|
||||||
return;
|
return; // Invalid event, but we can't log in header file
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy data based on event type
|
// Copy data based on event type
|
||||||
@@ -216,10 +216,12 @@ class BLEEvent {
|
|||||||
if (p == nullptr) {
|
if (p == nullptr) {
|
||||||
this->event_.gattc.gattc_param = nullptr;
|
this->event_.gattc.gattc_param = nullptr;
|
||||||
this->event_.gattc.data = nullptr;
|
this->event_.gattc.data = nullptr;
|
||||||
return;
|
return; // Invalid event, but we can't log in header file
|
||||||
}
|
}
|
||||||
|
|
||||||
// Heap-allocate param
|
// 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);
|
this->event_.gattc.gattc_param = new esp_ble_gattc_cb_param_t(*p);
|
||||||
|
|
||||||
// Copy data for events that need it
|
// Copy data for events that need it
|
||||||
@@ -247,10 +249,12 @@ class BLEEvent {
|
|||||||
if (p == nullptr) {
|
if (p == nullptr) {
|
||||||
this->event_.gatts.gatts_param = nullptr;
|
this->event_.gatts.gatts_param = nullptr;
|
||||||
this->event_.gatts.data = nullptr;
|
this->event_.gatts.data = nullptr;
|
||||||
return;
|
return; // Invalid event, but we can't log in header file
|
||||||
}
|
}
|
||||||
|
|
||||||
// Heap-allocate param
|
// 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);
|
this->event_.gatts.gatts_param = new esp_ble_gatts_cb_param_t(*p);
|
||||||
|
|
||||||
// Copy data for events that need it
|
// Copy data for events that need it
|
||||||
|
@@ -55,16 +55,13 @@ template<uint8_t SIZE> class BLEEventPool {
|
|||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return an event to the pool
|
// Return an event to the pool for reuse
|
||||||
void deallocate(BLEEvent *event) {
|
void release(BLEEvent *event) {
|
||||||
if (event == nullptr) {
|
if (event == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Events are reused - the load methods handle cleanup
|
|
||||||
// Just return to free list
|
|
||||||
this->free_list_.push(event);
|
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)
|
// Get total number of events created (high water mark)
|
||||||
|
Reference in New Issue
Block a user