mirror of
https://github.com/esphome/esphome.git
synced 2025-08-05 18:07:47 +00:00
safer
This commit is contained in:
parent
f23fd52a26
commit
c2599d7719
@ -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
|
// Still need to cancel existing timer if name is not empty
|
||||||
if (name_cstr != nullptr && name_cstr[0] != '\0') {
|
if (name_cstr != nullptr && name_cstr[0] != '\0') {
|
||||||
LockGuard guard{this->lock_};
|
LockGuard guard{this->lock_};
|
||||||
this->cancel_item_locked_(component, name_cstr, type, false);
|
this->cancel_item_locked_(component, name_cstr, type);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ void HOT Scheduler::set_timer_common_(Component *component, SchedulerItem::Type
|
|||||||
if (delay == 0 && type == SchedulerItem::TIMEOUT) {
|
if (delay == 0 && type == SchedulerItem::TIMEOUT) {
|
||||||
// Put in defer queue for guaranteed FIFO execution
|
// Put in defer queue for guaranteed FIFO execution
|
||||||
LockGuard guard{this->lock_};
|
LockGuard guard{this->lock_};
|
||||||
this->cancel_item_locked_(component, name_cstr, type, true);
|
this->cancel_item_locked_(component, name_cstr, type);
|
||||||
this->defer_queue_.push_back(std::move(item));
|
this->defer_queue_.push_back(std::move(item));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ void HOT Scheduler::set_timer_common_(Component *component, SchedulerItem::Type
|
|||||||
// If name is provided, do atomic cancel-and-add
|
// If name is provided, do atomic cancel-and-add
|
||||||
if (name_cstr != nullptr && name_cstr[0] != '\0') {
|
if (name_cstr != nullptr && name_cstr[0] != '\0') {
|
||||||
// Cancel existing items
|
// Cancel existing items
|
||||||
this->cancel_item_locked_(component, name_cstr, type, false);
|
this->cancel_item_locked_(component, name_cstr, type);
|
||||||
}
|
}
|
||||||
// Add new item directly to to_add_
|
// Add new item directly to to_add_
|
||||||
// since we have the lock held
|
// since we have the lock held
|
||||||
@ -448,12 +448,11 @@ bool HOT Scheduler::cancel_item_(Component *component, bool is_static_string, co
|
|||||||
|
|
||||||
// obtain lock because this function iterates and can be called from non-loop task context
|
// obtain lock because this function iterates and can be called from non-loop task context
|
||||||
LockGuard guard{this->lock_};
|
LockGuard guard{this->lock_};
|
||||||
return this->cancel_item_locked_(component, name_cstr, type, false);
|
return this->cancel_item_locked_(component, name_cstr, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to cancel items by name - must be called with lock held
|
// 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 HOT Scheduler::cancel_item_locked_(Component *component, const char *name_cstr, SchedulerItem::Type type) {
|
||||||
bool check_defer_only) {
|
|
||||||
size_t total_cancelled = 0;
|
size_t total_cancelled = 0;
|
||||||
|
|
||||||
// Check all containers for matching items
|
// Check all containers for matching items
|
||||||
@ -466,9 +465,6 @@ bool HOT Scheduler::cancel_item_locked_(Component *component, const char *name_c
|
|||||||
total_cancelled++;
|
total_cancelled++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (check_defer_only) {
|
|
||||||
return total_cancelled > 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ class Scheduler {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Helper to cancel items by name - must be called with lock held
|
// 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 check_defer_only);
|
bool cancel_item_locked_(Component *component, const char *name, SchedulerItem::Type type);
|
||||||
|
|
||||||
// Helper to extract name as const char* from either static string or std::string
|
// 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) {
|
inline const char *get_name_cstr_(bool is_static_string, const void *name_ptr) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user