Changeset 335 for libcaca/trunk/src/time.c
- Timestamp:
- Jan 11, 2004, 2:45:57 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/src/time.c
r331 r335 34 34 #include <time.h> 35 35 36 #if defined(USE_WIN32) 37 # include <windows.h> 38 #endif 39 40 #include <unistd.h> 41 36 42 #include "caca.h" 37 43 #include "caca_internals.h" 38 44 45 void _caca_sleep(unsigned int usec) 46 { 47 #if defined(HAVE_USLEEP) 48 usleep(usec); 49 #elif defined(HAVE_SLEEP) 50 Sleep(usec / 1000); 51 #else 52 SLEEP 53 #endif 54 } 55 39 56 unsigned int _caca_getticks(struct caca_timer *timer) 40 57 { 58 #if defined(HAVE_GETTIMEOFDAY) 41 59 struct timeval tv; 60 #elif defined(USE_WIN32) 61 static long long int freq = -1LL; 62 long long int usec; 63 #endif 42 64 unsigned int ticks = 0; 65 int new_sec, new_usec; 43 66 67 #if defined(HAVE_GETTIMEOFDAY) 44 68 gettimeofday(&tv, NULL); 69 new_sec = tv.tv_sec; 70 new_usec = tv.tv_usec; 71 #elif defined(USE_WIN32) 72 if(freq == -1LL) 73 { 74 if(!QueryPerformanceFrequency((LARGE_INTEGER *)&freq)) 75 freq = 0; 76 } 77 78 QueryPerformanceCounter((LARGE_INTEGER *)&usec); 79 new_sec = usec / freq; 80 new_usec = usec % freq; 81 #endif 45 82 46 83 if(timer->last_sec != 0) … … 48 85 /* If the delay was greater than 60 seconds, return 10 seconds 49 86 * otherwise we may overflow our ticks counter. */ 50 if( tv.tv_sec >= timer->last_sec + 60)87 if(new_sec >= timer->last_sec + 60) 51 88 ticks = 60 * 1000000; 52 89 else 53 90 { 54 ticks = ( tv.tv_sec - timer->last_sec) * 1000000;55 ticks += tv.tv_usec;91 ticks = (new_sec - timer->last_sec) * 1000000; 92 ticks += new_usec; 56 93 ticks -= timer->last_usec; 57 94 } 58 95 } 59 96 60 timer->last_sec = tv.tv_sec;61 timer->last_usec = tv.tv_usec;97 timer->last_sec = new_sec; 98 timer->last_usec = new_usec; 62 99 63 100 return ticks;
Note: See TracChangeset
for help on using the changeset viewer.