1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-09 23:02:23 +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;
}
while (!this->items_.empty()) {
// use scoping to indicate visibility of `item` variable
{
// Don't copy-by value yet
auto &item = this->items_[0];
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 cancelled
this->execute_item_(item.get(), now);
}
{
LockGuard guard{this->lock_};
// new scope, item from before might have been moved in the vector
auto item = std::move(this->items_[0]);
auto executed_item = std::move(this->items_[0]);
// Only pop after function call, this ensures we were reachable
// during the function call and know if we were cancelled.
this->pop_raw_();
if (item->remove) {
if (executed_item->remove) {
// We were removed/cancelled in the function call, stop
this->to_remove_--;
continue;
}
if (item->type == SchedulerItem::INTERVAL) {
item->set_next_execution(now_64 + item->interval);
if (executed_item->type == SchedulerItem::INTERVAL) {
executed_item->set_next_execution(now_64 + executed_item->interval);
// Add new item directly to to_add_
// since we have the lock held
this->to_add_.push_back(std::move(item));
this->to_add_.push_back(std::move(executed_item));
} else {
// Timeout completed - recycle it
this->recycle_item_(std::move(item));
this->recycle_item_(std::move(executed_item));
}
has_added_items |= !this->to_add_.empty();
}
}
if (has_added_items) {
this->process_to_add();