mirror of
https://github.com/esphome/esphome.git
synced 2025-08-09 11:57:46 +00:00
Merge branch 'extract_helpers' into integration
This commit is contained in:
commit
4f17a28ac5
@ -134,16 +134,13 @@ class BLEEvent {
|
||||
}
|
||||
|
||||
// Destructor to clean up heap allocations
|
||||
~BLEEvent() { this->cleanup_heap_data(); }
|
||||
~BLEEvent() { this->release(); }
|
||||
|
||||
// Default constructor for pre-allocation in pool
|
||||
BLEEvent() : type_(GAP) {}
|
||||
|
||||
// Invoked on return to EventPool
|
||||
void clear() { this->cleanup_heap_data(); }
|
||||
|
||||
// Clean up any heap-allocated data
|
||||
void cleanup_heap_data() {
|
||||
// Invoked on return to EventPool - clean up any heap-allocated data
|
||||
void release() {
|
||||
if (this->type_ == GAP) {
|
||||
return;
|
||||
}
|
||||
@ -164,19 +161,19 @@ class BLEEvent {
|
||||
|
||||
// Load new event data for reuse (replaces previous event data)
|
||||
void load_gap_event(esp_gap_ble_cb_event_t e, esp_ble_gap_cb_param_t *p) {
|
||||
this->cleanup_heap_data();
|
||||
this->release();
|
||||
this->type_ = GAP;
|
||||
this->init_gap_data_(e, p);
|
||||
}
|
||||
|
||||
void load_gattc_event(esp_gattc_cb_event_t e, esp_gatt_if_t i, esp_ble_gattc_cb_param_t *p) {
|
||||
this->cleanup_heap_data();
|
||||
this->release();
|
||||
this->type_ = GATTC;
|
||||
this->init_gattc_data_(e, i, p);
|
||||
}
|
||||
|
||||
void load_gatts_event(esp_gatts_cb_event_t e, esp_gatt_if_t i, esp_ble_gatts_cb_param_t *p) {
|
||||
this->cleanup_heap_data();
|
||||
this->release();
|
||||
this->type_ = GATTS;
|
||||
this->init_gatts_data_(e, i, p);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace esphome {
|
||||
|
||||
// Event Pool - On-demand pool of objects to avoid heap fragmentation
|
||||
// Events are allocated on first use and reused thereafter, growing to peak usage
|
||||
// @tparam T The type of objects managed by the pool (must have a clear() method)
|
||||
// @tparam T The type of objects managed by the pool (must have a release() method)
|
||||
// @tparam SIZE The maximum number of objects in the pool (1-255, limited by uint8_t)
|
||||
template<class T, uint8_t SIZE> class EventPool {
|
||||
public:
|
||||
@ -66,7 +66,7 @@ template<class T, uint8_t SIZE> class EventPool {
|
||||
void release(T *event) {
|
||||
if (event != nullptr) {
|
||||
// Clean up the event's allocated memory
|
||||
event->clear();
|
||||
event->release();
|
||||
this->free_list_.push(event);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user