summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2018-01-05 14:43:03 +0100
committerAlfred E. Heggestad <alfred.heggestad@gmail.com>2018-01-05 14:43:03 +0100
commit4b4920f542554755b3fc7af5fddbfef801bd8d2e (patch)
tree1854184fea792ed921f18d93b65f53a350938cef
parent82133bf1731ab6bcb65ce05e4fcdc2e36cfe0d95 (diff)
timer: add tmr_jiffies_usec
-rw-r--r--src/core.h7
-rw-r--r--src/srcs.mk1
-rw-r--r--src/timer.c52
3 files changed, 60 insertions, 0 deletions
diff --git a/src/core.h b/src/core.h
index 3c1ba2b..6e48e5d 100644
--- a/src/core.h
+++ b/src/core.h
@@ -540,3 +540,10 @@ static inline int timestamp_wrap(uint32_t ts_new, uint32_t ts_old)
return 0;
}
+
+
+/*
+ * Timer
+ */
+
+uint64_t tmr_jiffies_usec(void);
diff --git a/src/srcs.mk b/src/srcs.mk
index 4e9a2a7..86cbe8c 100644
--- a/src/srcs.mk
+++ b/src/srcs.mk
@@ -34,6 +34,7 @@ SRCS += rtpkeep.c
SRCS += sdp.c
SRCS += sipreq.c
SRCS += stream.c
+SRCS += timer.c
SRCS += ua.c
SRCS += ui.c
diff --git a/src/timer.c b/src/timer.c
new file mode 100644
index 0000000..bb49671
--- /dev/null
+++ b/src/timer.c
@@ -0,0 +1,52 @@
+/**
+ * @file timer.c Timer functions
+ *
+ * Copyright (C) 2010 Creytiv.com
+ */
+
+#define _BSD_SOURCE 1
+#define _DEFAULT_SOURCE 1
+#include <time.h>
+#include <re.h>
+#include <baresip.h>
+#include "core.h"
+
+
+/**
+ * Get the timer jiffies in microseconds [us]
+ *
+ * @return Jiffies in [us]
+ */
+uint64_t tmr_jiffies_usec(void)
+{
+ uint64_t jfs;
+
+#if defined(WIN32)
+ FILETIME ft;
+ ULARGE_INTEGER li;
+ GetSystemTimeAsFileTime(&ft);
+ li.LowPart = ft.dwLowDateTime;
+ li.HighPart = ft.dwHighDateTime;
+ jfs = li.QuadPart/10;
+#else
+ struct timespec now;
+ clockid_t clock_id;
+
+#if defined (CLOCK_BOOTTIME)
+ clock_id = CLOCK_BOOTTIME;
+#else
+ clock_id = CLOCK_MONOTONIC;
+#endif
+
+ if (0 != clock_gettime(clock_id, &now)) {
+ warning("timer: clock_gettime() failed (%m)\n", errno);
+ return 0;
+ }
+
+ jfs = (long)now.tv_sec * (uint64_t)1000000;
+ jfs += now.tv_nsec / (uint64_t)1000;
+
+#endif
+
+ return jfs;
+}