mirror of
https://github.com/esphome/esphome.git
synced 2025-09-17 18:52:19 +01:00
[scheduler] Fix timing accumulation in scheduler causing incorrect execution measurements
This commit is contained in:
@@ -345,7 +345,7 @@ void HOT Scheduler::call(uint32_t now) {
|
|||||||
// Execute callback without holding lock to prevent deadlocks
|
// Execute callback without holding lock to prevent deadlocks
|
||||||
// if the callback tries to call defer() again
|
// if the callback tries to call defer() again
|
||||||
if (!this->should_skip_item_(item.get())) {
|
if (!this->should_skip_item_(item.get())) {
|
||||||
this->execute_item_(item.get(), now);
|
now = this->execute_item_(item.get(), now);
|
||||||
}
|
}
|
||||||
// Recycle the defer item after execution
|
// Recycle the defer item after execution
|
||||||
this->recycle_item_(std::move(item));
|
this->recycle_item_(std::move(item));
|
||||||
@@ -483,7 +483,7 @@ void HOT Scheduler::call(uint32_t now) {
|
|||||||
// Warning: During callback(), a lot of stuff can happen, including:
|
// Warning: During callback(), a lot of stuff can happen, including:
|
||||||
// - 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);
|
now = this->execute_item_(item.get(), now);
|
||||||
|
|
||||||
LockGuard guard{this->lock_};
|
LockGuard guard{this->lock_};
|
||||||
|
|
||||||
@@ -568,11 +568,11 @@ void HOT Scheduler::pop_raw_() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper to execute a scheduler item
|
// Helper to execute a scheduler item
|
||||||
void HOT Scheduler::execute_item_(SchedulerItem *item, uint32_t now) {
|
uint32_t HOT Scheduler::execute_item_(SchedulerItem *item, uint32_t now) {
|
||||||
App.set_current_component(item->component);
|
App.set_current_component(item->component);
|
||||||
WarnIfComponentBlockingGuard guard{item->component, now};
|
WarnIfComponentBlockingGuard guard{item->component, now};
|
||||||
item->callback();
|
item->callback();
|
||||||
guard.finish();
|
return guard.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Common implementation for cancel operations
|
// Common implementation for cancel operations
|
||||||
|
@@ -254,7 +254,7 @@ class Scheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper to execute a scheduler item
|
// Helper to execute a scheduler item
|
||||||
void execute_item_(SchedulerItem *item, uint32_t now);
|
uint32_t execute_item_(SchedulerItem *item, uint32_t now);
|
||||||
|
|
||||||
// Helper to check if item should be skipped
|
// Helper to check if item should be skipped
|
||||||
bool should_skip_item_(SchedulerItem *item) const {
|
bool should_skip_item_(SchedulerItem *item) const {
|
||||||
|
Reference in New Issue
Block a user