From 869ed99dbc3a645fee6de36e97e1e12127068f10 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Thu, 8 Dec 2011 03:47:23 +0100 Subject: new event architecture, first trial --- tools.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'tools.c') diff --git a/tools.c b/tools.c index 8b39669..c2d8bd7 100644 --- a/tools.c +++ b/tools.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "tools.h" @@ -238,7 +239,6 @@ void *pcilib_datacpy32(void * dst, void const * src, uint8_t size, size_t n, pci } } - int pcilib_get_page_mask() { int pagesize,pagemask,temp; @@ -250,3 +250,40 @@ int pcilib_get_page_mask() { } return pagemask; } + +int calc_deadline(struct timeval *tv, pcilib_timeout_t timeout) { + gettimeofday(tv, NULL); + tv->tv_usec += timeout%1000000; + if (tv->tv_usec > 999999) { + tv->tv_usec -= 1000000; + tv->tv_sec = 1 + timeout/1000000; + } else { + tv->tv_sec = timeout/1000000; + } + + return 0; +} + +int check_deadline(struct timeval *tve, pcilib_timeout_t timeout) { + int64_t res; + struct timeval tvs; + + if (!tve->tv_sec) return 0; + + gettimeofday(&tvs, NULL); + res = ((tve->tv_sec - tvs.tv_sec)*1000000 + (tve->tv_usec - tvs.tv_usec)); + if (res < timeout) return 1; + + return 0; +} + +pcilib_timeout_t calc_time_to_deadline(struct timeval *tve) { + int64_t res; + struct timeval tvs; + + gettimeofday(&tvs, NULL); + res = ((tve->tv_sec - tvs.tv_sec)*1000000 + (tve->tv_usec - tvs.tv_usec)); + + if (res < 0) return 0; + return res; +} -- cgit v1.2.3