mirror of
https://github.com/esphome/esphome.git
synced 2026-03-01 02:14:19 -07:00
33bef139006bbd075975d00d7f734eedf1e87540
Restructure the defer queue processing loop to merge lock acquisitions. Previously each item required two separate lock/unlock pairs: one to move the item out of the queue, and one to recycle it after execution. This totaled 2N+1 lock acquisitions for N items. By combining the recycle of each item with the move-out of the next item under a single lock hold, the total drops to N+1. The callback still executes without the lock held to prevent deadlocks. Also adds an early return when the queue is empty to avoid taking the lock at all in the common case (nothing deferred). The lockless check is safe because the main loop is the single consumer of defer_queue_front_, and a stale size() read from a concurrent push can only cause us to see fewer items — they will be processed on the next loop iteration. Additionally outlines the rare defer queue compaction path into a separate noinline compact_defer_queue_locked_() to keep cold code out of the hot instruction cache lines.
Description
ESPHome is a system to control your ESP8266/ESP32 by simple yet powerful configuration files and control them remotely through Home Automation systems.
Readme
Multiple Licenses
524 MiB
Languages
C++
64.1%
Python
35.5%
C
0.3%
