timers: Remove GetRelativeTime()
[mplayer/glamo.git] / osdep / timer-linux.c
blobefcc6126276004da483a11172b3a9ee869208a11
1 // Precise timer routines for LINUX (C) LGB & A'rpi/ASTRAL
3 #include <unistd.h>
4 #ifdef __BEOS__
5 #define usleep(t) snooze(t)
6 #endif
7 #include <stdlib.h>
8 #include <time.h>
9 #include <sys/time.h>
10 #include "config.h"
12 const char timer_name[] =
13 #ifdef HAVE_NANOSLEEP
14 "nanosleep()";
15 #else
16 "usleep()";
17 #endif
19 int usec_sleep(int usec_delay)
21 #ifdef HAVE_NANOSLEEP
22 struct timespec ts;
23 ts.tv_sec = usec_delay / 1000000;
24 ts.tv_nsec = (usec_delay % 1000000) * 1000;
25 return nanosleep(&ts, NULL);
26 #else
27 return usleep(usec_delay);
28 #endif
31 // Returns current time in microseconds
32 unsigned int GetTimer(void){
33 struct timeval tv;
34 // float s;
35 gettimeofday(&tv,NULL);
36 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
37 return (tv.tv_sec*1000000+tv.tv_usec);
40 // Returns current time in milliseconds
41 unsigned int GetTimerMS(void){
42 struct timeval tv;
43 // float s;
44 gettimeofday(&tv,NULL);
45 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
46 return (tv.tv_sec*1000+tv.tv_usec/1000);
49 // Initialize timer, must be called at least once at start
50 void InitTimer(void){
54 #if 0
55 #include <stdio.h>
56 int main(void){
57 float t=0;
58 InitTimer();
59 while(1){ t+=GetRelativeTime();printf("time= %10.6f\r",t);fflush(stdout); }
61 #endif