From: Chris Dickens Date: Mon, 27 Apr 2015 09:16:28 +0000 (-0700) Subject: core: Miscellaneous transfer timeout improvements X-Git-Tag: upstream/1.0.21~174 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=02f7f859eec8aab0b680ad18d3aabd1fe24edb28;p=platform%2Fupstream%2Flibusb.git core: Miscellaneous transfer timeout improvements * When removing a transfer from the flying_transfers list, only rearm the timerfd if the transfer being removed was the first transfer *and* had a timeout. This is the only case where the timerfd should be altered by a transfer being removed. * When searching the flying_transfers list for the next timeout, searching can cease when the first transfer with an infinite timeout is encountered. Signed-off-by: Chris Dickens --- diff --git a/libusb/io.c b/libusb/io.c index 7c01fda..c71a2a2 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -1431,16 +1431,14 @@ out: static int remove_from_flying_list(struct usbi_transfer *transfer) { struct libusb_context *ctx = ITRANSFER_CTX(transfer); + int rearm_timerfd; int r = 0; - /* FIXME: could be more intelligent with the timerfd here. we don't need - * to disarm the timerfd if there was no timer running, and we only need - * to rearm the timerfd if the transfer that expired was the one with - * the shortest timeout. */ - usbi_mutex_lock(&ctx->flying_transfers_lock); + rearm_timerfd = (timerisset(&transfer->timeout) && + list_first_entry(&ctx->flying_transfers, struct usbi_transfer, list) == transfer); list_del(&transfer->list); - if (usbi_using_timerfd(ctx)) + if (usbi_using_timerfd(ctx) && rearm_timerfd) r = arm_timerfd_for_next_timeout(ctx); usbi_mutex_unlock(&ctx->flying_transfers_lock); @@ -2511,9 +2509,9 @@ int API_EXPORTED libusb_get_next_timeout(libusb_context *ctx, if (transfer->flags & (USBI_TRANSFER_TIMED_OUT | USBI_TRANSFER_OS_HANDLES_TIMEOUT)) continue; - /* no timeout for this transfer? */ + /* if we've reached transfers of infinte timeout, we're done looking */ if (!timerisset(&transfer->timeout)) - continue; + break; found = 1; break; diff --git a/libusb/version_nano.h b/libusb/version_nano.h index bfafef7..2db3257 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 10980 +#define LIBUSB_NANO 10981