27 alignof(F) <=
alignof(uintptr_t) && std::is_trivially_copyable_v<F>;
30 requires std::invocable<std::decay_t<F> &>
32 using D = std::decay_t<F>;
34 this->invoke_ = [](
SchedulerCallback *self) { (*std::launder(
reinterpret_cast<D *
>(self->bytes_)))(); };
35 ::new (this->
bytes_) D(std::forward<F>(f));
37 this->invoke_ = &SchedulerCallback::invoke_boxed;
38 this->
boxed_.obj = ::new D(std::forward<F>(f));
39 this->
boxed_.run = [](
void *
obj) { (*
static_cast<D *
>(
obj))(); };
40 if constexpr (std::is_trivially_destructible_v<D> &&
alignof(D) <= __STDCPP_DEFAULT_NEW_ALIGNMENT__) {
41 this->
boxed_.release =
static_cast<void (*)(
void *)
>(&::operator
delete);
43 this->
boxed_.release = [](
void *
obj) { ::delete
static_cast<D *
>(
obj); };
49#ifdef ESPHOME_DEBUG_SCHEDULER
52 if (this->invoke_ !=
nullptr)
62 void run_() { this->invoke_(
this); }
65 const bool boxed = this->invoke_ == &SchedulerCallback::invoke_boxed;
66#ifdef ESPHOME_DEBUG_SCHEDULER
67 this->invoke_ =
nullptr;
75 void take_(SchedulerCallback &other) {
76 this->invoke_ = other.invoke_;
77 auto *dst =
static_cast<unsigned char *
>(__builtin_assume_aligned(this->
bytes_,
alignof(uintptr_t)));
78 const auto *
src =
static_cast<const unsigned char *
>(__builtin_assume_aligned(other.bytes_,
alignof(uintptr_t)));
79 for (
size_t i = 0; i <
sizeof(this->
bytes_); i +=
sizeof(uintptr_t))
80 __builtin_memcpy(dst + i,
src + i,
sizeof(uintptr_t));
81#ifdef ESPHOME_DEBUG_SCHEDULER
82 other.invoke_ =
nullptr;
85#ifdef ESPHOME_DEBUG_SCHEDULER
86 [[noreturn]]
static void report_dropped();
88 static void invoke_boxed(SchedulerCallback *self) { self->boxed_.run(self->boxed_.obj); }