annotate osdep/timer-linux.c @ 36291:b2edfe1a11a6

Process events after destroying a window. This allows other windows to get their expose events.
author ib
date Thu, 01 Aug 2013 17:29:47 +0000
parents 514016233368
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28744
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
1 /*
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
2 * precise timer routines for Linux
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
3 * copyright (C) LGB & A'rpi/ASTRAL
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
4 *
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
5 * This file is part of MPlayer.
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
6 *
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
7 * MPlayer is free software; you can redistribute it and/or modify
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
8 * it under the terms of the GNU General Public License as published by
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
10 * (at your option) any later version.
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
11 *
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
12 * MPlayer is distributed in the hope that it will be useful,
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
15 * GNU General Public License for more details.
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
16 *
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
17 * You should have received a copy of the GNU General Public License along
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
18 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
20 */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 #include <unistd.h>
5297
f297030ef5ab include stdlib.h
arpi
parents: 4385
diff changeset
23 #include <stdlib.h>
2476
a6c5a537f30a a few warning fixes (missing #include's)
pl
parents: 2273
diff changeset
24 #include <time.h>
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 #include <sys/time.h>
16985
08cac43f1e38 Unify include paths, -I.. is in CFLAGS.
diego
parents: 13612
diff changeset
26 #include "config.h"
30554
321e9ea69b9f #include corresponding .h files in .c files.
diego
parents: 29157
diff changeset
27 #include "timer.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28
31464
1453fc56d49c Change timer_name type from char* to char[]; patch taken from Uoti's tree.
diego
parents: 31461
diff changeset
29 const char timer_name[] =
12954
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
30 #ifdef HAVE_NANOSLEEP
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
31 "nanosleep()";
12954
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
32 #else
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
33 "usleep()";
12954
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
34 #endif
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
35
2273
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
36 int usec_sleep(int usec_delay)
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
37 {
3090
57abb24ac58b HAVE_NANOSLEEP
alex
parents: 2476
diff changeset
38 #ifdef HAVE_NANOSLEEP
2273
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
39 struct timespec ts;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
40 ts.tv_sec = usec_delay / 1000000;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
41 ts.tv_nsec = (usec_delay % 1000000) * 1000;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
42 return nanosleep(&ts, NULL);
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
43 #else
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
44 return usleep(usec_delay);
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
45 #endif
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
46 }
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
47
99
fb1fc94eaff0 removed redundancy...
arpi_esp
parents: 1
diff changeset
48 // Returns current time in microseconds
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
49 unsigned int GetTimer(void)
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
50 {
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
51 struct timeval tv;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
52 //float s;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
53 gettimeofday(&tv,NULL);
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
54 //s = tv.tv_usec; s *= 0.000001; s += tv.tv_sec;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
55 return tv.tv_sec * 1000000 + tv.tv_usec;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
56 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57
4385
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
58 // Returns current time in milliseconds
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
59 unsigned int GetTimerMS(void)
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
60 {
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
61 struct timeval tv;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
62 //float s;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
63 gettimeofday(&tv,NULL);
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
64 //s = tv.tv_usec; s *= 0.000001; s += tv.tv_sec;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
65 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
66 }
4385
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
67
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
68 static unsigned int RelativeTime = 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 // Returns time spent between now and last call in seconds
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
71 float GetRelativeTime(void)
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
72 {
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
73 unsigned int t,r;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
74 t = GetTimer();
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
75 //t *= 16; printf("time = %ud\n", t);
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
76 r = t - RelativeTime;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
77 RelativeTime = t;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
78 return (float) r * 0.000001F;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 // Initialize timer, must be called at least once at start
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
82 void InitTimer(void)
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
83 {
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
84 GetRelativeTime();
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 }