FastLED 3.9.15
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
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
fl::u64 u64
Definition s16x16x4.h:221

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

108 {
109 Millis64State& state = get_millis64_state();
110 fl::u32 current_millis = fl::millis();
111 fl::unique_lock<fl::mutex> lock(state.mutex);
112
113 if (!state.initialized) {
114 // First call, set initial value
115 state.accumulated = current_millis;
116 state.last_millis = current_millis;
117 state.initialized = true;
118 return state.accumulated;
119 }
120
121 // Detect wraparound: current < last means 32-bit counter wrapped
122 // Delta calculation handles wraparound correctly via unsigned arithmetic
123 fl::u32 delta = current_millis - state.last_millis;
124
125 // Accumulate the delta into 64-bit counter
126 state.accumulated += delta;
127
128 // Update last value for next call
129 state.last_millis = current_millis;
130
131 return state.accumulated;
132}
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: