From 6c493d10d293a2b67a4f50c2dda06c5cae6f7fef Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Sun, 30 Jun 2019 12:18:27 +0200 Subject: [PATCH] More scheduler fixes --- esphome/core/scheduler.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/esphome/core/scheduler.cpp b/esphome/core/scheduler.cpp index a1a179e2d0..3df886cb5b 100644 --- a/esphome/core/scheduler.cpp +++ b/esphome/core/scheduler.cpp @@ -84,27 +84,32 @@ void ICACHE_RAM_ATTR HOT Scheduler::call() { // Uncomment for debugging the scheduler: - // if (random_uint32() % 400 == 0) { - // std::vector old_items = this->items_; - // ESP_LOGVV(TAG, "Items: (%u)", this->items_.size()); - // while (!this->empty_()) { - // auto *item = this->items_[0]; - // const char *type = item->type == SchedulerItem::INTERVAL ? "interval" : "timeout"; - // ESP_LOGVV(TAG, " %s '%s' interval=%u last_execution=%u next=%u", - // type, item->name.c_str(), item->interval, item->last_execution, item->last_execution + - // item->interval); - // this->pop_raw_(); - // } - // ESP_LOGVV(TAG, "\n"); - // this->items_ = old_items; + // if (random_uint32() % 400 == 0) { + // std::vector old_items = this->items_; + // ESP_LOGVV(TAG, "Items: count=%u, now=%u", this->items_.size(), now); + // while (!this->empty_()) { + // auto *item = this->items_[0]; + // const char *type = item->type == SchedulerItem::INTERVAL ? "interval" : "timeout"; + // ESP_LOGVV(TAG, " %s '%s' interval=%u last_execution=%u (%u) next=%u", + // type, item->name.c_str(), item->interval, item->last_execution, item->last_execution_major, + // item->last_execution + item->interval); + // this->pop_raw_(); // } + // ESP_LOGVV(TAG, "\n"); + // this->items_ = old_items; + //} while (!this->empty_()) { // Don't copy-by value yet auto *item = this->items_[0]; - if ((now - item->last_execution) < item->interval || item->last_execution_major != this->millis_major_) + if ((now - item->last_execution) < item->interval) // Not reached timeout yet, done for this call break; + uint8_t major = item->last_execution_major; + if (item->last_execution + item->interval < item->last_execution) + major++; + if (major != this->millis_major_) + break; // Don't run on failed components if (item->component != nullptr && item->component->is_failed()) {