Win32-Timer:
authorct@78566C00-6F59-1014-AAEE-A77C3B9AAB40
Thu, 12 May 2011 12:23:20 +0000
changeset 680 9a2474509269
parent 679 bb9fe2e2b2e1
child 681 3c42b5df66b1
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)
drivers/timers_win32/timers_win32.c
include/win32/timerscfg.h
--- 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);
 }
 
--- 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 <windows.h>
 
-// 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