summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2007-12-27 15:58:18 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2007-12-27 15:58:18 +0100
commit6f76e100383189eb9fd2b861fe2cdba2d94b7c59 (patch)
tree12e7ea996d4ed997c7a834a1bbe887fd419a99b5
parentbd411a6620f896b82494338e6386dd0324f63353 (diff)
downloadvdr-6f76e100383189eb9fd2b861fe2cdba2d94b7c59.tar.gz
vdr-6f76e100383189eb9fd2b861fe2cdba2d94b7c59.tar.bz2
cTimeMs now uses the monotonic clock, if available
-rw-r--r--CONTRIBUTORS1
-rw-r--r--HISTORY3
-rw-r--r--Makefile4
-rw-r--r--tools.c37
4 files changed, 41 insertions, 4 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 365e63e2..e7c84d43 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -1943,6 +1943,7 @@ Petri Hintukainen <Petri.Hintukainen@hut.fi>
for making cRemote::PutMacro() set a lock while it expands the macro
for pointing out that plugins from cRemote::PutMacro() and cRemote::CallPlugin()
need to be handled separately
+ for making cTimeMs use the monotonic clock
Marcel Schaeben <mts280@gmx.de>
for his "Easy Input" patch
diff --git a/HISTORY b/HISTORY
index 0ba9532e..504dabb3 100644
--- a/HISTORY
+++ b/HISTORY
@@ -5529,7 +5529,7 @@ Video Disk Recorder Revision History
- Fixed stopping live subtitles when a player is attached to the device.
- Fixed suddenly stopping subtitles in live mode.
-2007-11-25: Version 1.5.13
+2007-12-27: Version 1.5.13
- Fixed the declaration of cSubtitleObject::Decode8BppCodeString() (thanks to
Gregoire Favre).
@@ -5538,3 +5538,4 @@ Video Disk Recorder Revision History
- The kInfo key is now propagated to any open menu, so that it can react to it
in a context sensitive manner (suggested by Andreas Brugger). If there is
no menu open it will show the info of the current broadcast or replay.
+- cTimeMs now uses the monotonic clock, if available (thanks to Petri Hintukainen).
diff --git a/Makefile b/Makefile
index f32773c8..e986dd06 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@
# See the main source file 'vdr.c' for copyright information and
# how to reach the author.
#
-# $Id: Makefile 1.110 2007/11/04 10:15:59 kls Exp $
+# $Id: Makefile 1.111 2007/12/02 11:29:22 kls Exp $
.DELETE_ON_ERROR:
@@ -20,7 +20,7 @@ PREFIX ?= /usr/local
MANDIR = $(PREFIX)/share/man
BINDIR = $(PREFIX)/bin
LOCDIR = ./locale
-LIBS = -ljpeg -lpthread -ldl -lcap -lfreetype -lfontconfig
+LIBS = -ljpeg -lpthread -ldl -lcap -lrt -lfreetype -lfontconfig
INCLUDES = -I/usr/include/freetype2
PLUGINDIR= ./PLUGINS
diff --git a/tools.c b/tools.c
index ba7b0cf9..2f8e0789 100644
--- a/tools.c
+++ b/tools.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.c 1.137 2007/11/03 15:34:07 kls Exp $
+ * $Id: tools.c 1.138 2007/12/27 15:57:49 kls Exp $
*/
#include "tools.h"
@@ -545,6 +545,41 @@ cTimeMs::cTimeMs(int Ms)
uint64_t cTimeMs::Now(void)
{
+#if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK)
+#define MIN_RESOLUTION 5 // ms
+ static bool initialized = false;
+ static bool monotonic = false;
+ struct timespec tp;
+ if (!initialized) {
+ // check if monotonic timer is available and provides enough accurate resolution:
+ if (clock_getres(CLOCK_MONOTONIC, &tp) == 0) {
+ long Resolution = tp.tv_nsec;
+ // require a minimum resolution:
+ if (tp.tv_sec == 0 && tp.tv_nsec <= MIN_RESOLUTION * 1000000) {
+ if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) {
+ dsyslog("cTimeMs: using monotonic clock (resolution is %ld ns)", Resolution);
+ monotonic = true;
+ }
+ else
+ esyslog("cTimeMs: clock_gettime(CLOCK_MONOTONIC) failed");
+ }
+ else
+ dsyslog("cTimeMs: not using monotonic clock - resolution is too bad (%ld s %ld ns)", tp.tv_sec, tp.tv_nsec);
+ }
+ else
+ esyslog("cTimeMs: clock_getres(CLOCK_MONOTONIC) failed");
+ initialized = true;
+ }
+ if (monotonic) {
+ if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
+ return (uint64_t(tp.tv_sec)) * 1000 + tp.tv_nsec / 1000000;
+ esyslog("cTimeMs: clock_gettime(CLOCK_MONOTONIC) failed");
+ monotonic = false;
+ // fall back to gettimeofday()
+ }
+#else
+# warning Posix monotonic clock not available
+#endif
struct timeval t;
if (gettimeofday(&t, NULL) == 0)
return (uint64_t(t.tv_sec)) * 1000 + t.tv_usec / 1000;