| 106 | } |
| 107 | |
| 108 | fl::u64 millis64() { |
| 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 | } |
| 133 | |
| 134 | } // namespace fl |
no test coverage detected