drivers/timers_win32/timers_win32.c
changeset 719 438a979fda5d
parent 697 24a2aec61731
child 801 32d146b64a35
equal deleted inserted replaced
718:0b33d9cdbdeb 719:438a979fda5d
    36 
    36 
    37 #ifdef __cplusplus
    37 #ifdef __cplusplus
    38 };
    38 };
    39 #endif
    39 #endif
    40 
    40 
    41 struct _timeb timebuffer;
    41 DWORD timebuffer;
    42 
    42 
    43 /* Synchronization Object Implementation */
    43 /* Synchronization Object Implementation */
    44 CRITICAL_SECTION CanFestival_mutex;
    44 CRITICAL_SECTION CanFestival_mutex;
    45 HANDLE timer_thread = NULL;
    45 HANDLE timer_thread = NULL;
    46 HANDLE timer = NULL;
    46 HANDLE timer = NULL;
    47 
    47 
    48 int stop_timer=0;
    48 volatile int stop_timer=0;
    49 
    49 
    50 static TimerCallback_t init_callback;
    50 static TimerCallback_t init_callback;
    51 
    51 
    52 
    52 
    53 void EnterMutex(void)
    53 void EnterMutex(void)
    88 	while(!stop_timer)
    88 	while(!stop_timer)
    89 	{
    89 	{
    90 		WaitForSingleObject(timer, INFINITE);
    90 		WaitForSingleObject(timer, INFINITE);
    91 		if(stop_timer)
    91 		if(stop_timer)
    92 			break;
    92 			break;
    93 		_ftime(&timebuffer);
       
    94 		EnterMutex();
    93 		EnterMutex();
       
    94 		timebuffer = GetTickCount();
    95 		TimeDispatch();
    95 		TimeDispatch();
    96 		LeaveMutex();
    96 		LeaveMutex();
    97 	}
    97 	}
    98 	return 0;
    98 	return 0;
    99 }
    99 }
   110     {
   110     {
   111         printf("CreateWaitableTimer failed (%d)\n", GetLastError());
   111         printf("CreateWaitableTimer failed (%d)\n", GetLastError());
   112     }
   112     }
   113 
   113 
   114 	// Take first absolute time ref in milliseconds.
   114 	// Take first absolute time ref in milliseconds.
   115 	_ftime(&timebuffer);
   115 	timebuffer = GetTickCount();
   116 }
   116 }
   117 
   117 
   118 void TimerCleanup(void)
   118 void TimerCleanup(void)
   119 {
   119 {
   120 	DeleteCriticalSection(&CanFestival_mutex);
   120 	DeleteCriticalSection(&CanFestival_mutex);
   156 	else
   156 	else
   157 	{
   157 	{
   158 		LARGE_INTEGER liDueTime;
   158 		LARGE_INTEGER liDueTime;
   159 
   159 
   160 		/* arg 2 of SetWaitableTimer take 100 ns interval */
   160 		/* arg 2 of SetWaitableTimer take 100 ns interval */
   161 		liDueTime.QuadPart = (-1 * value);
   161 		liDueTime.QuadPart = ((long long) (-1) * value * 10000);
   162 		//printf("SetTimer(%llu)\n", value);
   162 		//printf("SetTimer(%llu)\n", value);
   163 
   163 
   164 		if (!SetWaitableTimer(timer, &liDueTime, 0, NULL, NULL, FALSE))
   164 		if (!SetWaitableTimer(timer, &liDueTime, 0, NULL, NULL, FALSE))
   165 		{
   165 		{
   166 			printf("SetWaitableTimer failed (%d)\n", GetLastError());
   166 			printf("SetWaitableTimer failed (%d)\n", GetLastError());
   169 }
   169 }
   170 
   170 
   171 /* Get the elapsed time since the last occured alarm */
   171 /* Get the elapsed time since the last occured alarm */
   172 TIMEVAL getElapsedTime(void)
   172 TIMEVAL getElapsedTime(void)
   173 {
   173 {
   174 	struct _timeb timetmp;
   174   DWORD timetmp = GetTickCount();
   175 	_ftime(&timetmp);
   175   return (timetmp - timebuffer);
   176 	return (timetmp.time - timebuffer.time) * 10000000 + (timetmp.millitm - timebuffer.millitm) * 10000;
       
   177 }
   176 }
   178 
   177