# HG changeset patch # User ct@78566C00-6F59-1014-AAEE-A77C3B9AAB40 # Date 1305203000 0 # Node ID 9a2474509269e7fd708dacb829e28718a57d4770 # Parent bb9fe2e2b2e1fb33cb947c0f2cc2b5156f9d39d5 Win32-Timer: CHANGED: - Timer implementation for win32 from absolute time (_ftime) to GetTickCount(). This fixes the following bug: When the system time was changed, a heartbeat timeout occurred. FIXED: - Timeout seems only work properly if EnterMutex() is called before call of GetTickCount() (Patch from Roland Marquis) diff -r bb9fe2e2b2e1 -r 9a2474509269 drivers/timers_win32/timers_win32.c --- a/drivers/timers_win32/timers_win32.c Thu Dec 22 13:46:00 2011 +0100 +++ b/drivers/timers_win32/timers_win32.c Thu May 12 12:23:20 2011 +0000 @@ -38,7 +38,7 @@ }; #endif -struct _timeb timebuffer; +DWORD timebuffer; /* Synchronization Object Implementation */ CRITICAL_SECTION CanFestival_mutex; @@ -90,8 +90,8 @@ WaitForSingleObject(timer, INFINITE); if(stop_timer) break; - _ftime(&timebuffer); EnterMutex(); + timebuffer = GetTickCount(); TimeDispatch(); LeaveMutex(); } @@ -112,7 +112,7 @@ } // Take first absolute time ref in milliseconds. - _ftime(&timebuffer); + timebuffer = GetTickCount(); } void TimerCleanup(void) @@ -158,7 +158,7 @@ LARGE_INTEGER liDueTime; /* arg 2 of SetWaitableTimer take 100 ns interval */ - liDueTime.QuadPart = (-1 * value); + liDueTime.QuadPart = ((long long) (-1) * value * 10000); //printf("SetTimer(%llu)\n", value); if (!SetWaitableTimer(timer, &liDueTime, 0, NULL, NULL, FALSE)) @@ -171,8 +171,7 @@ /* Get the elapsed time since the last occured alarm */ TIMEVAL getElapsedTime(void) { - struct _timeb timetmp; - _ftime(&timetmp); - return (timetmp.time - timebuffer.time) * 10000000 + (timetmp.millitm - timebuffer.millitm) * 10000; + DWORD timetmp = GetTickCount(); + return (timetmp - timebuffer); } diff -r bb9fe2e2b2e1 -r 9a2474509269 include/win32/timerscfg.h --- a/include/win32/timerscfg.h Thu Dec 22 13:46:00 2011 +0100 +++ b/include/win32/timerscfg.h Thu May 12 12:23:20 2011 +0000 @@ -26,12 +26,12 @@ #include -// Time unit : 100 ns -#define TIMEVAL unsigned long long +// Time unit : 1msec +#define TIMEVAL DWORD #define TIMEVAL_MAX ~(TIMEVAL)0 -#define MS_TO_TIMEVAL(ms) ms*10000 -#define US_TO_TIMEVAL(us) us*10 +#define MS_TO_TIMEVAL(ms) ms +#define US_TO_TIMEVAL(us) (us / 1000) #define TASK_HANDLE HANDLE