FastLED 3.10.6
Loading...
Searching...
No Matches

◆ millis64()

fl::u64 fl::millis64 ( )

64-bit millisecond timer - returns milliseconds since system startup without wraparound

This function provides a 64-bit millisecond counter that never wraps around in any practical timeframe (584 million years). It's built on top of fl::millis() and automatically detects and corrects for 32-bit wraparound.

The implementation uses a function-local static for thread-safe accumulation on platforms that support it. On platforms with native 64-bit timers, this function may be optimized to use the native implementation directly.

Returns
Number of milliseconds since system startup as a 64-bit value
Note
Thread-safe on platforms with proper static initialization guards
No wraparound in practical usage (584+ million years)
Slightly higher overhead than millis() due to wraparound detection

Examples

// Long-running timing without wraparound concerns
fl::u64 start = fl::millis64();
long_running_operation();
fl::u64 elapsed = fl::millis64() - start;
// Safe duration tracking across 49+ day boundaries
static fl::u64 session_start = fl::millis64();
fl::u64 uptime = fl::millis64() - session_start; // Never wraps
// Timestamps for logging and analytics
fl::u64 event_time = fl::millis64();
log_event("operation_complete", event_time);
fl::u64 millis64()
64-bit millisecond timer - returns milliseconds since system startup without wraparound

Definition at line 172 of file chrono.cpp.hpp.

172 {
173 Millis64State& state = get_millis64_state();
174 fl::u32 current_millis = fl::millis();
175 fl::unique_lock<fl::mutex> lock(state.mutex);
176
177 if (!state.initialized) {
178 // First call, set initial value
179 state.accumulated = current_millis;
180 state.last_millis = current_millis;
181 state.initialized = true;
182 return state.accumulated;
183 }
184
185 // Detect wraparound: current < last means 32-bit counter wrapped
186 // Delta calculation handles wraparound correctly via unsigned arithmetic
187 fl::u32 delta = current_millis - state.last_millis;
188
189 // Accumulate the delta into 64-bit counter
190 state.accumulated += delta;
191
192 // Update last value for next call
193 state.last_millis = current_millis;
194
195 return state.accumulated;
196}
TestState state
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.

References millis(), millis64(), and state.

Referenced by millis64(), and time().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: