annotate linux/timer-lx.c @ 4324:09f15844c960

don't render UV planes if interleaved (also add support later)
author alex
date Wed, 23 Jan 2002 19:32:52 +0000
parents 57abb24ac58b
children 7bb8f7905000
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 // Precise timer routines for LINUX (C) LGB & A'rpi/ASTRAL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 #include <unistd.h>
2476
a6c5a537f30a a few warning fixes (missing #include's)
pl
parents: 2273
diff changeset
4 #include <time.h>
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 #include <sys/time.h>
3090
57abb24ac58b HAVE_NANOSLEEP
alex
parents: 2476
diff changeset
6 #include "../config.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7
2273
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
8 int usec_sleep(int usec_delay)
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
9 {
3090
57abb24ac58b HAVE_NANOSLEEP
alex
parents: 2476
diff changeset
10 #ifdef HAVE_NANOSLEEP
2273
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
11 struct timespec ts;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
12 ts.tv_sec = usec_delay / 1000000;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
13 ts.tv_nsec = (usec_delay % 1000000) * 1000;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
14 return nanosleep(&ts, NULL);
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
15 #else
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
16 return usleep(usec_delay);
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
17 #endif
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
18 }
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
19
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
20
99
fb1fc94eaff0 removed redundancy...
arpi_esp
parents: 1
diff changeset
21 // Returns current time in microseconds
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 unsigned int GetTimer(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 struct timeval tv;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 struct timezone tz;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 // float s;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 gettimeofday(&tv,&tz);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 return (tv.tv_sec*1000000+tv.tv_usec);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 static unsigned int RelativeTime=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 // Returns time spent between now and last call in seconds
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 float GetRelativeTime(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 unsigned int t,r;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 t=GetTimer();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 // t*=16;printf("time=%ud\n",t);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 r=t-RelativeTime;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 RelativeTime=t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 return (float)r * 0.000001F;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 // Initialize timer, must be called at least once at start
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 void InitTimer(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 GetRelativeTime();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 void main(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 float t=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 InitTimer();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 while(1){ t+=GetRelativeTime();printf("time= %10.6f\r",t);fflush(stdout); }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56