diff options
author | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2011-12-08 03:47:23 +0100 |
---|---|---|
committer | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2011-12-08 03:47:23 +0100 |
commit | 869ed99dbc3a645fee6de36e97e1e12127068f10 (patch) | |
tree | fa4a4e7ef977a3d3621ff5e96fb664e6fbc9e6fe /tools.c | |
parent | ddc77c1e819eee03a13efff4a9aa3161485f3f1f (diff) | |
download | pcitool-869ed99dbc3a645fee6de36e97e1e12127068f10.tar.gz pcitool-869ed99dbc3a645fee6de36e97e1e12127068f10.tar.bz2 pcitool-869ed99dbc3a645fee6de36e97e1e12127068f10.tar.xz pcitool-869ed99dbc3a645fee6de36e97e1e12127068f10.zip |
new event architecture, first trial
Diffstat (limited to 'tools.c')
-rw-r--r-- | tools.c | 39 |
1 files changed, 38 insertions, 1 deletions
@@ -5,6 +5,7 @@ #include <assert.h> #include <ctype.h> #include <arpa/inet.h> +#include <sys/time.h> #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; +} |