diff --git a/esphome/core/scheduler.h b/esphome/core/scheduler.h index 5071144691..b48c130d78 100644 --- a/esphome/core/scheduler.h +++ b/esphome/core/scheduler.h @@ -282,8 +282,7 @@ class Scheduler { // Helper to mark matching items in a container as removed // Returns the number of items marked for removal - // For ESPHOME_THREAD_MULTI_NO_ATOMICS platforms, the caller must hold the scheduler lock before calling this - // function. + // IMPORTANT: Caller must hold the scheduler lock before calling this function. template size_t mark_matching_items_removed_(Container &container, Component *component, const char *name_cstr, SchedulerItem::Type type, bool match_retry) { @@ -291,8 +290,8 @@ class Scheduler { for (auto &item : container) { // Skip nullptr items (can happen in defer_queue_ when items are being processed) // The defer_queue_ uses index-based processing: items are std::moved out but left in the - // vector as nullptr until cleanup. If cancel_item_locked_() is called from a callback during - // defer queue processing, it will iterate over these nullptr items. This check prevents crashes. + // vector as nullptr until cleanup. Even though this function is called with lock held, + // the vector can still contain nullptr items from the processing loop. This check prevents crashes. if (!item) continue; if (this->matches_item_(item, component, name_cstr, type, match_retry)) {