Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/hx/StdLibs.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Array<unsigned char> __hxcpp_resource_bytes(String inName);
// System access
Array<String> __get_args();
double __time_stamp();
::cpp::Int64 __time_stamp_ms();

HXCPP_EXTERN_CLASS_ATTRIBUTES void __hxcpp_print_string(const String &inV);
HXCPP_EXTERN_CLASS_ATTRIBUTES void __hxcpp_println_string(const String &inV);
Expand Down
34 changes: 30 additions & 4 deletions src/hx/StdLibs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,17 @@ int __hxcpp_irand(int inMax)
return (lo | (mid<<12) | (hi<<24) ) % inMax;
}

#ifdef HX_WINDOWS
LARGE_INTEGER qpcFrequency;
#endif

void __hxcpp_stdlibs_boot()
{
#ifdef HX_WINDOWS
// MSDN states that QueryPerformanceFrequency will always succeed on XP and above, so I'm ignoring the result.
QueryPerformanceFrequency(&qpcFrequency);
#endif

#if defined(_MSC_VER) && !defined(HX_WINRT)
HMODULE kernel32 = LoadLibraryA("kernel32");
if (kernel32)
Expand Down Expand Up @@ -327,10 +336,7 @@ double __time_stamp()
if (t0==0)
{
t0 = now;
__int64 freq;
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
if (freq!=0)
period = 1.0/freq;
period = 1.0/qpcFrequency.QuadPart;
}
if (period!=0)
return (now-t0)*period;
Expand All @@ -349,6 +355,26 @@ double __time_stamp()
#endif
}

::cpp::Int64 __time_stamp_ms()
{
#ifdef HX_WINDOWS
// MSDN states that QueryPerformanceCounter will always succeed on XP and above, so I'm ignoring the result.
auto now = LARGE_INTEGER{ 0 };
QueryPerformanceCounter(&now);

return now.QuadPart * LONGLONG{ 1000 } / qpcFrequency.QuadPart;
#else
auto time = timespec();

if (clock_gettime(CLOCK_MONOTONIC, &time))
{
throw ::Dynamic(HX_CSTRING("Failed to get the monotonic clock time"));
}

return time.tv_sec * 1000 + (time.tv_nsec / 1000000);
#endif
}

#if defined(HX_WINDOWS) && !defined(HX_WINRT)

/*
Expand Down