From bb51031ec66f4caffef0fc0d7fbd4625f65b5a04 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 6 Jul 2025 21:23:30 -0500 Subject: [PATCH] preen --- esphome/core/scheduler.cpp | 6 +++--- esphome/core/scheduler.h | 10 ++-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/esphome/core/scheduler.cpp b/esphome/core/scheduler.cpp index f093c11042..f67b3d7198 100644 --- a/esphome/core/scheduler.cpp +++ b/esphome/core/scheduler.cpp @@ -68,7 +68,7 @@ void HOT Scheduler::set_timer_common_(Component *component, SchedulerItem::Type // Still need to cancel existing timer if name is not empty if (name_cstr != nullptr && name_cstr[0] != '\0') { LockGuard guard{this->lock_}; - this->cancel_item_locked_(component, name_cstr, type, delay == 0 && type == SchedulerItem::TIMEOUT); + this->cancel_item_locked_(component, name_cstr, type, false); } return; } @@ -451,7 +451,7 @@ bool HOT Scheduler::cancel_item_(Component *component, bool is_static_string, co // Helper to cancel items by name - must be called with lock held bool HOT Scheduler::cancel_item_locked_(Component *component, const char *name_cstr, SchedulerItem::Type type, - bool defer_only) { + bool check_defer_only) { size_t total_cancelled = 0; // Check all containers for matching items @@ -464,7 +464,7 @@ bool HOT Scheduler::cancel_item_locked_(Component *component, const char *name_c total_cancelled++; } } - if (defer_only) { + if (check_defer_only) { return total_cancelled > 0; } } diff --git a/esphome/core/scheduler.h b/esphome/core/scheduler.h index cdb6431f89..7e16f66423 100644 --- a/esphome/core/scheduler.h +++ b/esphome/core/scheduler.h @@ -99,13 +99,7 @@ class Scheduler { SchedulerItem(const SchedulerItem &) = delete; SchedulerItem &operator=(const SchedulerItem &) = delete; - // Delete move operations to prevent accidental moves of SchedulerItem objects. - // This is intentional because: - // 1. SchedulerItem contains a dynamically allocated name that requires careful ownership management - // 2. The scheduler only moves unique_ptr, never SchedulerItem objects directly - // 3. Moving unique_ptr only transfers pointer ownership without moving the pointed-to object - // 4. Deleting these operations makes it explicit that SchedulerItem objects should not be moved - // 5. This prevents potential double-free bugs if the code is refactored to move SchedulerItem objects + // Delete move operations: SchedulerItem objects are only managed via unique_ptr, never moved directly SchedulerItem(SchedulerItem &&) = delete; SchedulerItem &operator=(SchedulerItem &&) = delete; @@ -149,7 +143,7 @@ class Scheduler { private: // Helper to cancel items by name - must be called with lock held - bool cancel_item_locked_(Component *component, const char *name, SchedulerItem::Type type, bool defer_only); + bool cancel_item_locked_(Component *component, const char *name, SchedulerItem::Type type, bool check_defer_only); // Helper to extract name as const char* from either static string or std::string inline const char *get_name_cstr_(bool is_static_string, const void *name_ptr) {