@@ -242,8 +242,17 @@ int __hxcpp_irand(int inMax)
242242 return (lo | (mid<<12 ) | (hi<<24 ) ) % inMax;
243243}
244244
245+ #ifdef HX_WINDOWS
246+ LARGE_INTEGER qpcFrequency;
247+ #endif
248+
245249void __hxcpp_stdlibs_boot ()
246250{
251+ #ifdef HX_WINDOWS
252+ // MSDN states that QueryPerformanceFrequency will always succeed on XP and above, so I'm ignoring the result.
253+ QueryPerformanceFrequency (&qpcFrequency);
254+ #endif
255+
247256 #if defined(_MSC_VER) && !defined(HX_WINRT)
248257 HMODULE kernel32 = LoadLibraryA (" kernel32" );
249258 if (kernel32)
@@ -327,10 +336,7 @@ double __time_stamp()
327336 if (t0==0 )
328337 {
329338 t0 = now;
330- __int64 freq;
331- QueryPerformanceFrequency ((LARGE_INTEGER*)&freq);
332- if (freq!=0 )
333- period = 1.0 /freq;
339+ period = 1.0 /qpcFrequency.QuadPart ;
334340 }
335341 if (period!=0 )
336342 return (now-t0)*period;
@@ -349,6 +355,26 @@ double __time_stamp()
349355#endif
350356}
351357
358+ ::cpp::Int64 __time_stamp_ms ()
359+ {
360+ #ifdef HX_WINDOWS
361+ // MSDN states that QueryPerformanceCounter will always succeed on XP and above, so I'm ignoring the result.
362+ auto now = LARGE_INTEGER{ 0 };
363+ QueryPerformanceCounter (&now);
364+
365+ return now.QuadPart * LONGLONG{ 1000 } / qpcFrequency.QuadPart ;
366+ #else
367+ auto time = timespec ();
368+
369+ if (clock_gettime (CLOCK_MONOTONIC, &time))
370+ {
371+ throw ::Dynamic (HX_CSTRING (" Failed to get the monotonic clock time" ));
372+ }
373+
374+ return time.tv_sec * 1000 + (time.tv_nsec / 1000000 );
375+ #endif
376+ }
377+
352378#if defined(HX_WINDOWS) && !defined(HX_WINRT)
353379
354380/*
0 commit comments