@@ -165,7 +165,7 @@ Mono_Time *mono_time_new(const Memory *mem, mono_time_current_time_cb *current_t
165165 // Maximum reproducibility. Never return time = 0.
166166 mono_time -> base_time = 1 ;
167167#else
168- mono_time -> base_time = (uint64_t )time (nullptr ) - ( current_time_monotonic (mono_time ) / 1000ULL );
168+ mono_time -> base_time = (uint64_t )time (nullptr ) * 1000ULL - current_time_monotonic (mono_time );
169169#endif
170170
171171 mono_time_update (mono_time );
@@ -190,14 +190,13 @@ void mono_time_free(const Memory *mem, Mono_Time *mono_time)
190190
191191void mono_time_update (Mono_Time * mono_time )
192192{
193- uint64_t cur_time = 0 ;
194193#ifdef OS_WIN32
195194 /* we actually want to update the overflow state of mono_time here */
196195 pthread_mutex_lock (& mono_time -> last_clock_lock );
197196 mono_time -> last_clock_update = true;
198197#endif
199- cur_time = mono_time -> current_time_callback ( mono_time -> user_data ) / 1000ULL ;
200- cur_time += mono_time -> base_time ;
198+ const uint64_t cur_time =
199+ mono_time -> base_time + mono_time -> current_time_callback ( mono_time -> user_data ) ;
201200#ifdef OS_WIN32
202201 pthread_mutex_unlock (& mono_time -> last_clock_lock );
203202#endif
@@ -211,21 +210,22 @@ void mono_time_update(Mono_Time *mono_time)
211210#endif
212211}
213212
214- uint64_t mono_time_get (const Mono_Time * mono_time )
213+ uint64_t mono_time_get_ms (const Mono_Time * mono_time )
215214{
216- #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
215+ #if !defined( ESP_PLATFORM ) && !defined( FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION )
217216 // Fuzzing is only single thread for now, no locking needed */
218- return mono_time -> cur_time ;
219- #else
220- #ifndef ESP_PLATFORM
221217 pthread_rwlock_rdlock (mono_time -> time_update_lock );
222218#endif
223219 const uint64_t cur_time = mono_time -> cur_time ;
224- #ifndef ESP_PLATFORM
220+ #if !defined( ESP_PLATFORM ) && !defined( FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION )
225221 pthread_rwlock_unlock (mono_time -> time_update_lock );
226222#endif
227223 return cur_time ;
228- #endif
224+ }
225+
226+ uint64_t mono_time_get (const Mono_Time * mono_time )
227+ {
228+ return mono_time_get_ms (mono_time ) / 1000ULL ;
229229}
230230
231231bool mono_time_is_timeout (const Mono_Time * mono_time , uint64_t timestamp , uint64_t timeout )
@@ -245,9 +245,10 @@ void mono_time_set_current_time_callback(Mono_Time *mono_time,
245245 }
246246}
247247
248- /**
249- * Return current monotonic time in milliseconds (ms). The starting point is
250- * unspecified.
248+ /** @brief Return current monotonic time in milliseconds (ms).
249+ *
250+ * The starting point is unspecified and in particular is likely not comparable
251+ * to the return value of `mono_time_get_ms()`.
251252 */
252253uint64_t current_time_monotonic (Mono_Time * mono_time )
253254{
0 commit comments