use GetSystemTimeAsFileTime instead of _ftime on Windows

It seems that _ftime has devolved to only giving 1-second resolution
on Windows 7.  GetSystemTimeAsFileTime does better, so that's what
we'll use.
This commit is contained in:
Joel Dice 2010-10-28 20:30:49 -06:00
parent 5cbfee467c
commit 5ade8d1cf6

View File

@ -36,9 +36,6 @@
# define isnan _isnan # define isnan _isnan
# define isfinite _finite # define isfinite _finite
# define strtof strtod # define strtof strtod
# define FTIME _ftime_s
# else
# define FTIME _ftime
# endif # endif
#else // not PLATFORM_WINDOWS #else // not PLATFORM_WINDOWS
@ -469,9 +466,13 @@ extern "C" JNIEXPORT jlong JNICALL
Java_java_lang_System_currentTimeMillis(JNIEnv*, jclass) Java_java_lang_System_currentTimeMillis(JNIEnv*, jclass)
{ {
#ifdef PLATFORM_WINDOWS #ifdef PLATFORM_WINDOWS
_timeb tb; // We used to use _ftime here, but that only gives us 1-second
FTIME(&tb); // resolution on Windows 7. _ftime_s might work better, but MinGW
return (static_cast<jlong>(tb.time) * 1000) + static_cast<jlong>(tb.millitm); // doesn't have it as of this writing. So we use this mess instead:
FILETIME time;
GetSystemTimeAsFileTime(&time);
return (((static_cast<jlong>(time.dwHighDateTime) << 32)
| time.dwLowDateTime) / 10000) - 11644473600000LL;
#else #else
timeval tv = { 0, 0 }; timeval tv = { 0, 0 };
gettimeofday(&tv, 0); gettimeofday(&tv, 0);