mirror of
https://github.com/esphome/esphome.git
synced 2026-09-22 12:38:40 +00:00
[core] Freshen loop_component_start_time_ before scheduler dispatch
This commit is contained in:
@@ -103,6 +103,12 @@ class Application {
|
||||
void set_current_component(Component *component) { this->current_component_ = component; }
|
||||
Component *get_current_component() { return this->current_component_; }
|
||||
|
||||
/// Update the cached loop component start time. Used by the scheduler before
|
||||
/// dispatching a queued callback so callers reading
|
||||
/// get_loop_component_start_time() inside the callback observe a fresh value
|
||||
/// instead of one inherited from the prior loop iteration's last component.
|
||||
void set_loop_component_start_time(uint32_t now) { this->loop_component_start_time_ = now; }
|
||||
|
||||
// Entity register methods (generated from entity_types.h).
|
||||
// Each entity type gets two overloads:
|
||||
// - register_<entity>(obj) — bare push_back
|
||||
|
||||
@@ -772,6 +772,11 @@ Scheduler::SchedulerItem *HOT Scheduler::pop_raw_locked_() {
|
||||
// Helper to execute a scheduler item
|
||||
uint32_t HOT Scheduler::execute_item_(SchedulerItem *item, uint32_t now) {
|
||||
App.set_current_component(item->component);
|
||||
// Freshen the cached loop component start time so callbacks reading
|
||||
// App.get_loop_component_start_time() observe the dispatch time of this
|
||||
// item rather than a stale value from the prior loop iteration's last
|
||||
// component phase.
|
||||
App.set_loop_component_start_time(now);
|
||||
WarnIfComponentBlockingGuard guard{item->component, now};
|
||||
item->callback();
|
||||
uint32_t end = guard.finish();
|
||||
|
||||
Reference in New Issue
Block a user