diff options
author | Chris Dickens <christopher.a.dickens@gmail.com> | 2015-04-27 02:16:28 -0700 |
---|---|---|
committer | Chris Dickens <christopher.a.dickens@gmail.com> | 2015-05-07 12:34:35 -0700 |
commit | 02f7f859eec8aab0b680ad18d3aabd1fe24edb28 (patch) | |
tree | 34d386fbe8d538e02f5e33e291fa8c971d51a5e7 | |
parent | a1c9895543b6aa3deb6e42e7be83121b28f298ce (diff) | |
download | libusb-02f7f859eec8aab0b680ad18d3aabd1fe24edb28.tar.gz |
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 <christopher.a.dickens@gmail.com>
-rw-r--r-- | libusb/io.c | 14 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
2 files changed, 7 insertions, 9 deletions
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 |