1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 14:43:51 +00:00

Scheduler fixes (#813)

* Scheduler fixes

Fixes https://github.com/esphome/issues/issues/789, fixes https://github.com/esphome/issues/issues/788

Also changes to use unique_ptr - this should be much safer than the raw pointers form before (though the scoping rules might cause some issues, but looking closely I didn't find anything)

* Disable debugging

* Format
This commit is contained in:
Otto Winter
2019-10-31 20:25:16 +01:00
committed by GitHub
parent 864c5d8908
commit 560251ab2a
2 changed files with 112 additions and 85 deletions

View File

@@ -2,6 +2,7 @@
#include "esphome/core/component.h"
#include <vector>
#include <memory>
namespace esphome {
@@ -34,21 +35,30 @@ class Scheduler {
bool remove;
uint8_t last_execution_major;
static bool cmp(SchedulerItem *a, SchedulerItem *b);
inline uint32_t next_execution() { return this->last_execution + this->timeout; }
inline uint8_t next_execution_major() {
uint32_t next_exec = this->next_execution();
uint8_t next_exec_major = this->last_execution_major;
if (next_exec < this->last_execution)
next_exec_major++;
return next_exec_major;
}
static bool cmp(const std::unique_ptr<SchedulerItem> &a, const std::unique_ptr<SchedulerItem> &b);
};
uint32_t millis_();
void cleanup_();
void pop_raw_();
void push_(SchedulerItem *item);
void push_(std::unique_ptr<SchedulerItem> item);
bool cancel_item_(Component *component, const std::string &name, SchedulerItem::Type type);
bool empty_() {
this->cleanup_();
return this->items_.empty();
}
std::vector<SchedulerItem *> items_;
std::vector<SchedulerItem *> to_add_;
std::vector<std::unique_ptr<SchedulerItem>> items_;
std::vector<std::unique_ptr<SchedulerItem>> to_add_;
uint32_t last_millis_{0};
uint8_t millis_major_{0};
};