--- ../../vdr-1.4.5-orig/tools.c 2007-01-02 06:18:41.000000000 +0200 +++ ../../vdr-1.4.5/tools.c 2007-01-02 06:14:03.000000000 +0200 @@ -549,6 +549,54 @@ uint64_t cTimeMs::Now(void) { +#if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK) + static bool initialized = false; + static bool monotonic = false; + struct timespec tp; + + // initialization: + // check if monotonic timer is available and + // provides enough accurate resolution + if(!initialized) { + + if(clock_getres(CLOCK_MONOTONIC, &tp)) + esyslog("cTimeMs: clock_getres(CLOCK_MONOTONIC) failed"); + + else { + dsyslog("cTimeMs: clock_gettime(CLOCK_MONOTONIC): clock resolution %d us", + ((int)tp.tv_nsec) / 1000); + + // require at least 1 ms resolution + if( tp.tv_sec == 0 && tp.tv_nsec <= 1000000 ) { + + if(clock_gettime(CLOCK_MONOTONIC, &tp)) + esyslog("cTimeMs: clock_gettime(CLOCL_MONOTONIC) failed"); + + else { + dsyslog("cTimeMs: using monotonic clock"); + monotonic = true; + } + } + } + + initialized = true; + } + + + if(monotonic) { + + if(!clock_gettime(CLOCK_MONOTONIC, &tp)) + return (uint64_t(tp.tv_sec)) * 1000 + tp.tv_nsec / 1000000; + + esyslog("cTimeMs: clock_gettime(CLOCK_MONOTONIC) failed"); + monotonic = false; + //return 0; + } + +#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;