summaryrefslogtreecommitdiffstats
path: root/plugins/alsa/time_utils.c
diff options
context:
space:
mode:
authorThierry Bultel <thierry.bultel@iot.bzh>2018-07-20 12:25:22 +0200
committerThierry Bultel <thierry.bultel@iot.bzh>2018-07-20 12:25:22 +0200
commit712b3a2cda69422931b26283054e476e3d554a06 (patch)
tree108906755159da8c87c8d4d3fa0871b134c4c35d /plugins/alsa/time_utils.c
parentafc7d62d02c523f3d3adc29f713f5a4395ca3f58 (diff)
added ringbuffer and time utils
Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
Diffstat (limited to 'plugins/alsa/time_utils.c')
-rw-r--r--plugins/alsa/time_utils.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/plugins/alsa/time_utils.c b/plugins/alsa/time_utils.c
new file mode 100644
index 0000000..6f22e9d
--- /dev/null
+++ b/plugins/alsa/time_utils.c
@@ -0,0 +1,17 @@
+#include "time_utils.h"
+#include "time.h"
+
+__thread uint64_t last = 0;
+
+uint64_t now_monotonic_usec() {
+ struct timespec now;
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ return now.tv_sec*1000000+now.tv_nsec/1000;
+}
+
+uint64_t ts() {
+ uint64_t now = now_monotonic_usec();
+ uint64_t elapsed = now-last;
+ last = now;
+ return elapsed;
+}