[scheduler][core] Address review: use preloaded major

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.
This commit is contained in:
J. Nick Koston
2026-04-23 06:34:40 -05:00
parent 3bfde7249a
commit c6d888e4d2
+4 -2
View File
@@ -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<uint16_t>(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 */