fixed #1017: improve win32 timing accuracy

This commit is contained in:
minggo 2012-03-06 14:12:57 +08:00
parent 74b4b14ee3
commit a0f0971782
1 changed files with 5 additions and 14 deletions

View File

@ -30,20 +30,11 @@ int CC_DLL gettimeofday(struct timeval * val, struct timezone *)
{
if (val)
{
SYSTEMTIME wtm;
GetLocalTime(&wtm);
struct tm tTm;
tTm.tm_year = wtm.wYear - 1900;
tTm.tm_mon = wtm.wMonth - 1;
tTm.tm_mday = wtm.wDay;
tTm.tm_hour = wtm.wHour;
tTm.tm_min = wtm.wMinute;
tTm.tm_sec = wtm.wSecond;
tTm.tm_isdst = -1;
val->tv_sec = (long)mktime(&tTm); // time_t is 64-bit on win32
val->tv_usec = wtm.wMilliseconds * 1000;
LARGE_INTEGER liTime, liFreq;
QueryPerformanceFrequency( &liFreq );
QueryPerformanceCounter( &liTime );
val->tv_sec = (long)( liTime.QuadPart / liFreq.QuadPart );
val->tv_usec = (long)( liTime.QuadPart * 1000000.0 / liFreq.QuadPart - val->tv_sec * 1000000.0 );
}
return 0;
}