mirror of
https://github.com/esphome/esphome.git
synced 2025-08-06 10:27:49 +00:00
fix race
This commit is contained in:
parent
6bb32c2e61
commit
a71030c4de
@ -65,13 +65,13 @@ void HOT Scheduler::set_timer_common_(Component *component, SchedulerItem::Type
|
|||||||
const char *name_cstr =
|
const char *name_cstr =
|
||||||
is_static_string ? static_cast<const char *>(name_ptr) : static_cast<const std::string *>(name_ptr)->c_str();
|
is_static_string ? static_cast<const char *>(name_ptr) : static_cast<const std::string *>(name_ptr)->c_str();
|
||||||
|
|
||||||
// Cancel existing timer if name is not empty
|
if (delay == SCHEDULER_DONT_RUN) {
|
||||||
if (name_cstr != nullptr && name_cstr[0] != '\0') {
|
// Cancel existing timer if name is not empty
|
||||||
this->cancel_item_(component, name_cstr, type);
|
if (name_cstr != nullptr && name_cstr[0] != '\0') {
|
||||||
}
|
this->cancel_item_(component, name_cstr, type);
|
||||||
|
}
|
||||||
if (delay == SCHEDULER_DONT_RUN)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto now = this->millis_();
|
const auto now = this->millis_();
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
@ -135,10 +136,12 @@ class Scheduler {
|
|||||||
void set_timer_common_(Component *component, SchedulerItem::Type type, bool is_static_string, const void *name_ptr,
|
void set_timer_common_(Component *component, SchedulerItem::Type type, bool is_static_string, const void *name_ptr,
|
||||||
uint32_t delay, std::function<void()> func);
|
uint32_t delay, std::function<void()> func);
|
||||||
|
|
||||||
|
// Helper to cancel items by name - must be called with lock held
|
||||||
|
bool cancel_item_locked_(Component *component, const char *name, SchedulerItem::Type type);
|
||||||
|
|
||||||
uint64_t millis_();
|
uint64_t millis_();
|
||||||
void cleanup_();
|
void cleanup_();
|
||||||
void pop_raw_();
|
void pop_raw_();
|
||||||
void push_(std::unique_ptr<SchedulerItem> item);
|
|
||||||
// Common implementation for cancel operations
|
// Common implementation for cancel operations
|
||||||
bool cancel_item_common_(Component *component, bool is_static_string, const void *name_ptr, SchedulerItem::Type type);
|
bool cancel_item_common_(Component *component, bool is_static_string, const void *name_ptr, SchedulerItem::Type type);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user