diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2004-12-19 18:08:09 +0100 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2004-12-19 18:08:09 +0100 |
commit | c49253824a46a45dac86d2a0404b9d5c6e1a92a4 (patch) | |
tree | c81bb3537cd4670d6eddc062d0f0f92a43ade8d2 /tools.c | |
parent | ce8369251cf64919a7f1a8333201d87f92fb2f14 (diff) | |
download | vdr-c49253824a46a45dac86d2a0404b9d5c6e1a92a4.tar.gz vdr-c49253824a46a45dac86d2a0404b9d5c6e1a92a4.tar.bz2 |
Replaced time_ms() with a threadsafe and non-overflowing cTimeMs
Diffstat (limited to 'tools.c')
-rw-r--r-- | tools.c | 44 |
1 files changed, 31 insertions, 13 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.c 1.84 2004/12/19 17:19:46 kls Exp $ + * $Id: tools.c 1.85 2004/12/19 18:06:16 kls Exp $ */ #include "tools.h" @@ -187,18 +187,6 @@ int numdigits(int n) return strlen(buf); } -int time_ms(void) -{ - static time_t t0 = 0; - struct timeval t; - if (gettimeofday(&t, NULL) == 0) { - if (t0 == 0) - t0 = t.tv_sec; // this avoids an overflow (we only work with deltas) - return (t.tv_sec - t0) * 1000 + t.tv_usec / 1000; - } - return 0; -} - bool isnumber(const char *s) { if (!*s) @@ -432,6 +420,36 @@ time_t LastModifiedTime(const char *FileName) return 0; } +// --- cTimeMs --------------------------------------------------------------- + +cTimeMs::cTimeMs(void) +{ + Set(); +} + +void cTimeMs::Set(int Ms) +{ + begin = Now() + Ms; +} + +bool cTimeMs::TimedOut(void) +{ + return Now() >= begin; +} + +uint64 cTimeMs::Now(void) +{ + struct timeval t; + if (gettimeofday(&t, NULL) == 0) + return (uint64(t.tv_sec)) * 1000 + t.tv_usec / 1000; + return 0; +} + +uint64 cTimeMs::Elapsed(void) +{ + return Now() - begin; +} + // --- cBufferedStringFunction ----------------------------------------------- cBufferedStringFunction::cBufferedStringFunction(void) |