From c6d888e4d28ab184b1fbcacc837123ba26f0cf53 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 23 Apr 2026 06:34:40 -0500 Subject: [PATCH] [scheduler][core] Address review: use preloaded major MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In time_64.cpp's true-rollover branch, bump the just-loaded `major` local first and __atomic_store_n that value to millis_major, instead of reading the global again for the store expression. Equivalent under the held lock; clearer and avoids a second read. scheduler.h indent: the NO_ATOMICS #else branch bodies read at 2 spaces while the sibling #ifdef/#elif branches read at 4. clang-format refuses to normalise these consistently — every manual re-indent to 4 spaces gets reverted by the hook. Leaving as clang-format produces it. --- esphome/core/time_64.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/esphome/core/time_64.cpp b/esphome/core/time_64.cpp index c18ccd44f84..cf651c3e91a 100644 --- a/esphome/core/time_64.cpp +++ b/esphome/core/time_64.cpp @@ -96,9 +96,11 @@ uint64_t Millis64Impl::compute(uint32_t now) { major = __atomic_load_n(&millis_major, __ATOMIC_RELAXED); if (now < last && (last - now) > HALF_MAX_UINT32) { - // True rollover detected (happens every ~49.7 days) - __atomic_store_n(&millis_major, static_cast(millis_major + 1), __ATOMIC_RELAXED); + // True rollover detected (happens every ~49.7 days). + // Use the already-loaded `major` local; avoids a second read of the + // global (equivalent under the held lock). major++; + __atomic_store_n(&millis_major, major, __ATOMIC_RELAXED); #ifdef ESPHOME_DEBUG_SCHEDULER ESP_LOGD(TAG, "Detected true 32-bit rollover at %" PRIu32 "ms (was %" PRIu32 ")", now, last); #endif /* ESPHOME_DEBUG_SCHEDULER */