summaryrefslogtreecommitdiffstats
path: root/src/libtimer/timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libtimer/timer.c')
-rw-r--r--src/libtimer/timer.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/libtimer/timer.c b/src/libtimer/timer.c
index 955d790..174533f 100644
--- a/src/libtimer/timer.c
+++ b/src/libtimer/timer.c
@@ -21,7 +21,9 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/time.h>
+//#include <sys/time.h>
+#include <time.h>
+#include <errno.h>
#include "timer.h"
static struct timer *timer_head = NULL;
@@ -29,11 +31,11 @@ static struct timer **timer_tail_p = &timer_head;
double get_time(void)
{
- struct timeval tv;
+ static struct timespec tv;
- gettimeofday(&tv, NULL);
+ clock_gettime(CLOCK_REALTIME, &tv);
- return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
+ return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000.0;
}
void timer_init(struct timer *timer, void (*fn)(struct timer *timer), void *priv)
@@ -66,15 +68,11 @@ void timer_exit(struct timer *timer)
void timer_start(struct timer *timer, double duration)
{
- struct timeval tv;
-
if (!timer->linked) {
fprintf(stderr, "Timer is not initialized, aborting!\n");
abort();
}
- gettimeofday(&tv, NULL);
-
timer->duration = duration;
timer->timeout = get_time() + duration;
}