diff --git a/esphome/core/event_pool.h b/esphome/core/event_pool.h index 39537267ca..6d61e9a80d 100644 --- a/esphome/core/event_pool.h +++ b/esphome/core/event_pool.h @@ -18,8 +18,12 @@ template class EventPool { ~EventPool() { // Clean up any remaining events in the free list T *event; + RAMAllocator allocator(RAMAllocator::ALLOC_INTERNAL); while ((event = this->free_list_.pop()) != nullptr) { - delete event; + // Call destructor + event->~T(); + // Deallocate using RAMAllocator + allocator.deallocate(event, 1); } } diff --git a/esphome/core/lock_free_queue.h b/esphome/core/lock_free_queue.h index ec26d268a0..ede7496737 100644 --- a/esphome/core/lock_free_queue.h +++ b/esphome/core/lock_free_queue.h @@ -94,6 +94,9 @@ template class LockFreeQueue { return next_tail == head_.load(std::memory_order_acquire); } + // Set the FreeRTOS task handle to notify when items are pushed to the queue + // This enables efficient wake-up of a consumer task that's waiting for data + // @param task The FreeRTOS task handle to notify, or nullptr to disable notifications void set_task_to_notify(TaskHandle_t task) { task_to_notify_ = task; } protected: