mirror of
https://github.com/esphome/esphome.git
synced 2025-08-05 18:07:47 +00:00
preen
This commit is contained in:
parent
3ca956cd6a
commit
4c1b8c8b96
@ -401,15 +401,6 @@ void HOT Scheduler::pop_raw_() {
|
|||||||
std::pop_heap(this->items_.begin(), this->items_.end(), SchedulerItem::cmp);
|
std::pop_heap(this->items_.begin(), this->items_.end(), SchedulerItem::cmp);
|
||||||
this->items_.pop_back();
|
this->items_.pop_back();
|
||||||
}
|
}
|
||||||
// Helper function to check if item matches criteria for cancellation
|
|
||||||
bool HOT Scheduler::matches_item_(const std::unique_ptr<SchedulerItem> &item, Component *component,
|
|
||||||
const char *name_cstr, SchedulerItem::Type type) {
|
|
||||||
if (item->component != component || item->type != type || item->remove) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const char *item_name = item->get_name();
|
|
||||||
return item_name != nullptr && strcmp(name_cstr, item_name) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper to execute a scheduler item
|
// Helper to execute a scheduler item
|
||||||
void HOT Scheduler::execute_item_(SchedulerItem *item) {
|
void HOT Scheduler::execute_item_(SchedulerItem *item) {
|
||||||
@ -437,37 +428,41 @@ bool HOT Scheduler::cancel_item_(Component *component, bool is_static_string, co
|
|||||||
return this->cancel_item_locked_(component, name_cstr, type);
|
return this->cancel_item_locked_(component, name_cstr, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper to mark items for cancellation and return count
|
||||||
|
template<typename Container>
|
||||||
|
size_t HOT Scheduler::mark_items_for_removal_(Container &items, Component *component, const char *name_cstr,
|
||||||
|
SchedulerItem::Type type) {
|
||||||
|
size_t cancelled_count = 0;
|
||||||
|
for (auto &item : items) {
|
||||||
|
if (item->component != component || item->type != type || item->remove) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const char *item_name = item->get_name();
|
||||||
|
if (item_name != nullptr && strcmp(name_cstr, item_name) == 0) {
|
||||||
|
item->remove = true;
|
||||||
|
cancelled_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cancelled_count;
|
||||||
|
}
|
||||||
|
|
||||||
// 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 ret = false;
|
size_t total_cancelled = 0;
|
||||||
|
|
||||||
// Check all containers for matching items
|
// Check all containers for matching items
|
||||||
#if !defined(USE_ESP8266) && !defined(USE_RP2040)
|
#if !defined(USE_ESP8266) && !defined(USE_RP2040)
|
||||||
// Only check defer_queue_ on platforms that have it
|
// Only check defer_queue_ on platforms that have it
|
||||||
for (auto &item : this->defer_queue_) {
|
total_cancelled += this->mark_items_for_removal_(this->defer_queue_, component, name_cstr, type);
|
||||||
if (this->matches_item_(item, component, name_cstr, type)) {
|
|
||||||
item->remove = true;
|
|
||||||
ret = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (auto &item : this->items_) {
|
size_t items_cancelled = this->mark_items_for_removal_(this->items_, component, name_cstr, type);
|
||||||
if (this->matches_item_(item, component, name_cstr, type)) {
|
this->to_remove_ += items_cancelled; // Only track removals for heap items
|
||||||
item->remove = true;
|
total_cancelled += items_cancelled;
|
||||||
ret = true;
|
|
||||||
this->to_remove_++; // Only track removals for heap items
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &item : this->to_add_) {
|
total_cancelled += this->mark_items_for_removal_(this->to_add_, component, name_cstr, type);
|
||||||
if (this->matches_item_(item, component, name_cstr, type)) {
|
|
||||||
item->remove = true;
|
|
||||||
ret = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return total_cancelled > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Scheduler::millis_() {
|
uint64_t Scheduler::millis_() {
|
||||||
|
@ -140,6 +140,11 @@ class Scheduler {
|
|||||||
// 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 cancel_item_locked_(Component *component, const char *name, SchedulerItem::Type type);
|
||||||
|
|
||||||
|
// Helper to mark items for cancellation and return count
|
||||||
|
template<typename Container>
|
||||||
|
size_t mark_items_for_removal_(Container &items, Component *component, const char *name_cstr,
|
||||||
|
SchedulerItem::Type type);
|
||||||
|
|
||||||
uint64_t millis_();
|
uint64_t millis_();
|
||||||
void cleanup_();
|
void cleanup_();
|
||||||
void pop_raw_();
|
void pop_raw_();
|
||||||
@ -147,10 +152,6 @@ class Scheduler {
|
|||||||
bool cancel_item_(Component *component, bool is_static_string, const void *name_ptr, SchedulerItem::Type type);
|
bool cancel_item_(Component *component, bool is_static_string, const void *name_ptr, SchedulerItem::Type type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Helper functions for cancel operations
|
|
||||||
bool matches_item_(const std::unique_ptr<SchedulerItem> &item, Component *component, const char *name_cstr,
|
|
||||||
SchedulerItem::Type type);
|
|
||||||
|
|
||||||
// Helper to execute a scheduler item
|
// Helper to execute a scheduler item
|
||||||
void execute_item_(SchedulerItem *item);
|
void execute_item_(SchedulerItem *item);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user