1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-10 15:22:24 +01:00

Merge branch 'integration' into memory_api

This commit is contained in:
J. Nick Koston
2025-09-07 22:03:07 -05:00

View File

@@ -436,8 +436,6 @@ void HOT Scheduler::call(uint32_t now) {
this->to_remove_ = 0; this->to_remove_ = 0;
} }
while (!this->items_.empty()) { while (!this->items_.empty()) {
// use scoping to indicate visibility of `item` variable
{
// Don't copy-by value yet // Don't copy-by value yet
auto &item = this->items_[0]; auto &item = this->items_[0];
if (item->get_next_execution() > now_64) { if (item->get_next_execution() > now_64) {
@@ -486,36 +484,32 @@ void HOT Scheduler::call(uint32_t now) {
// - timeouts/intervals get added, potentially invalidating vector pointers // - timeouts/intervals get added, potentially invalidating vector pointers
// - timeouts/intervals get cancelled // - timeouts/intervals get cancelled
this->execute_item_(item.get(), now); this->execute_item_(item.get(), now);
}
{
LockGuard guard{this->lock_}; LockGuard guard{this->lock_};
// new scope, item from before might have been moved in the vector auto executed_item = std::move(this->items_[0]);
auto item = std::move(this->items_[0]);
// Only pop after function call, this ensures we were reachable // Only pop after function call, this ensures we were reachable
// during the function call and know if we were cancelled. // during the function call and know if we were cancelled.
this->pop_raw_(); this->pop_raw_();
if (item->remove) { if (executed_item->remove) {
// We were removed/cancelled in the function call, stop // We were removed/cancelled in the function call, stop
this->to_remove_--; this->to_remove_--;
continue; continue;
} }
if (item->type == SchedulerItem::INTERVAL) { if (executed_item->type == SchedulerItem::INTERVAL) {
item->set_next_execution(now_64 + item->interval); executed_item->set_next_execution(now_64 + executed_item->interval);
// 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
this->to_add_.push_back(std::move(item)); this->to_add_.push_back(std::move(executed_item));
} else { } else {
// Timeout completed - recycle it // Timeout completed - recycle it
this->recycle_item_(std::move(item)); this->recycle_item_(std::move(executed_item));
} }
has_added_items |= !this->to_add_.empty(); has_added_items |= !this->to_add_.empty();
} }
}
if (has_added_items) { if (has_added_items) {
this->process_to_add(); this->process_to_add();