From db84d8e8dc1aa216e235b25ab9e68c85ff452ce8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 6 Jul 2025 18:49:41 -0500 Subject: [PATCH] tweak --- esphome/core/scheduler.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/esphome/core/scheduler.cpp b/esphome/core/scheduler.cpp index be8f7db83f..0c4a4ff230 100644 --- a/esphome/core/scheduler.cpp +++ b/esphome/core/scheduler.cpp @@ -123,17 +123,15 @@ void HOT Scheduler::set_timer_common_(Component *component, SchedulerItem::Type } #endif - { - LockGuard guard{this->lock_}; - // If name is provided, do atomic cancel-and-add - if (name_cstr != nullptr && name_cstr[0] != '\0') { - // Cancel existing items - this->cancel_item_locked_(component, name_cstr, type, false); - } - // Add new item directly to to_add_ - // since we have the lock held - this->to_add_.push_back(std::move(item)); + LockGuard guard{this->lock_}; + // If name is provided, do atomic cancel-and-add + if (name_cstr != nullptr && name_cstr[0] != '\0') { + // Cancel existing items + this->cancel_item_locked_(component, name_cstr, type, false); } + // Add new item directly to to_add_ + // since we have the lock held + this->to_add_.push_back(std::move(item)); } void HOT Scheduler::set_timeout(Component *component, const char *name, uint32_t timeout, std::function func) {