summaryrefslogtreecommitdiff
path: root/libusb/libusbi.h
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2020-03-05 23:19:55 -0800
committerChris Dickens <christopher.a.dickens@gmail.com>2020-03-05 23:19:55 -0800
commit0b3a2ed92d45a78a13b5abce61d87d0d43ce09d8 (patch)
tree1513d71f6efa9bafcb071b620d416a917511dd00 /libusb/libusbi.h
parentec01c28e1e892b410bdd1581a2bd4e46cbd03eac (diff)
downloadlibusb-0b3a2ed92d45a78a13b5abce61d87d0d43ce09d8.tar.gz
core: Switch usbi_transfer to store timeout as timespec
The transfer timeout is structured around time values provided by the clock_gettime() function. This function uses a timespec structure, but the usbi_transfer structure was storing its calculated timeout in a timeval structure. This mismatch introduces extra work when checking for transfer timeouts as there must be a conversion between these two structures. Eliminate this by storing the calculated timeout as a timespec, thus allowing direct comparison. Note that a conversion to a timeval is still necessary in the libusb_get_next_timeout() function because the public API uses a timeval structure, but this is now the only place where such a conversion is done. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Diffstat (limited to 'libusb/libusbi.h')
-rw-r--r--libusb/libusbi.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index c60b201..da9334f 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -207,7 +207,21 @@ static inline void *usbi_reallocf(void *ptr, size_t size)
return ret;
}
-#define TIMESPEC_IS_SET(ts) ((ts)->tv_sec != 0 || (ts)->tv_nsec != 0)
+#define TIMESPEC_IS_SET(ts) ((ts)->tv_sec || (ts)->tv_nsec)
+#define TIMESPEC_CLEAR(ts) (ts)->tv_sec = (ts)->tv_nsec = 0
+#define TIMESPEC_CMP(a, b, CMP) \
+ (((a)->tv_sec == (b)->tv_sec) \
+ ? ((a)->tv_nsec CMP (b)->tv_nsec) \
+ : ((a)->tv_sec CMP (b)->tv_sec))
+#define TIMESPEC_SUB(a, b, result) \
+ do { \
+ (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
+ (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \
+ if ((result)->tv_nsec < 0L) { \
+ --(result)->tv_sec; \
+ (result)->tv_nsec += 1000000000L; \
+ } \
+ } while (0)
#if defined(OS_WINDOWS)
#define TIMEVAL_TV_SEC_TYPE long
@@ -459,7 +473,7 @@ struct usbi_transfer {
int num_iso_packets;
struct list_head list;
struct list_head completed_list;
- struct timeval timeout;
+ struct timespec timeout;
int transferred;
uint32_t stream_id;
uint32_t state_flags; /* Protected by usbi_transfer->lock */