summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libusb/io.c60
1 files changed, 4 insertions, 56 deletions
diff --git a/libusb/io.c b/libusb/io.c
index 0b32beb..728d85f 100644
--- a/libusb/io.c
+++ b/libusb/io.c
@@ -1711,10 +1711,6 @@ static int handle_timeouts(struct libusb_context *ctx)
return 0;
}
#else
-/* Note: there is code duplication between handle_timeouts_locked and
- * handle_timeouts, as tranfer cancellation from the backend requires
- * flying_transfers locks that are not set wholesale */
-#ifndef OS_WINDOWS
static int handle_timeouts_locked(struct libusb_context *ctx)
{
int r;
@@ -1756,63 +1752,15 @@ static int handle_timeouts_locked(struct libusb_context *ctx)
}
return 0;
}
-#endif
static int handle_timeouts(struct libusb_context *ctx)
{
int r;
- struct timespec systime_ts;
- struct timeval systime;
- struct usbi_transfer *transfer, *to_handle;
USBI_GET_CONTEXT(ctx);
-
- if (list_empty(&ctx->flying_transfers))
- return 0;
-
- /* get current time */
- r = usbi_backend->clock_gettime(USBI_CLOCK_MONOTONIC, &systime_ts);
- if (r < 0)
- return r;
-
- TIMESPEC_TO_TIMEVAL(&systime, &systime_ts);
-
- /* iterate through flying transfers list, finding all transfers that
- * have expired timeouts. Same trick as usbi_handle_disconnect() so
- * that usbi_handle_transfer_cancellation() can be called in cancel()
- * on the backend. */
- while (1) {
- to_handle = NULL;
- pthread_mutex_lock(&ctx->flying_transfers_lock);
-
- list_for_each_entry(transfer, &ctx->flying_transfers, list, struct usbi_transfer) {
- struct timeval *cur_tv = &transfer->timeout;
-
- /* if we've reached transfers of infinite timeout, we're all done */
- if (!timerisset(cur_tv))
- break;
-
- /* ignore timeouts we've already handled */
- if (transfer->flags & USBI_TRANSFER_TIMED_OUT)
- continue;
-
- /* if transfer has non-expired timeout, nothing more to do */
- if ((cur_tv->tv_sec > systime.tv_sec) ||
- (cur_tv->tv_sec == systime.tv_sec &&
- cur_tv->tv_usec > systime.tv_usec))
- break;
-
- to_handle = transfer;
- break;
- }
- pthread_mutex_unlock(&ctx->flying_transfers_lock);
-
- if (!to_handle)
- break;
-
- /* otherwise, we've got an expired timeout to handle */
- handle_timeout(to_handle);
- }
- return 0;
+ pthread_mutex_lock(&ctx->flying_transfers_lock);
+ r = handle_timeouts_locked(ctx);
+ pthread_mutex_unlock(&ctx->flying_transfers_lock);
+ return r;
}
#endif