summaryrefslogtreecommitdiff
path: root/tools.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2004-12-19 18:08:09 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2004-12-19 18:08:09 +0100
commitc49253824a46a45dac86d2a0404b9d5c6e1a92a4 (patch)
treec81bb3537cd4670d6eddc062d0f0f92a43ade8d2 /tools.c
parentce8369251cf64919a7f1a8333201d87f92fb2f14 (diff)
downloadvdr-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.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/tools.c b/tools.c
index 3776e6b9..fb95e7df 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.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)