Before this patch if ie multiple hot-plug events were pending, multiple handle_events calls would be necessary to handle them all, this patch changes handle_events so that the poll is re-done to check for more events if there was activity on any of the special fds.
Signed-off-by: Hans de Goede <hdego...@redhat.com> --- libusb/io.c | 10 ++++++++++ libusb/version_nano.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libusb/io.c b/libusb/io.c index 982882e..15ede36 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -1967,6 +1967,7 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv) struct pollfd *fds = NULL; int i = -1; int timeout_ms; + int special_event; usbi_mutex_lock(&ctx->pollfds_lock); list_for_each_entry(ipollfd, &ctx->pollfds, list, struct usbi_pollfd) @@ -1996,6 +1997,7 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv) if (tv->tv_usec % 1000) timeout_ms++; +redo_poll: usbi_dbg("poll() %d fds with timeout in %dms", nfds, timeout_ms); r = usbi_poll(fds, nfds, timeout_ms); usbi_dbg("poll() returned %d", r); @@ -2011,12 +2013,15 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv) return LIBUSB_ERROR_IO; } + special_event = 0; + /* fd[0] is always the ctrl pipe */ if (fds[0].revents) { /* another thread wanted to interrupt event handling, and it succeeded! * handle any other events that cropped up at the same time, and * simply return */ usbi_dbg("caught a fish on the control pipe"); + special_event = 1; if (r == 1) { r = 0; @@ -2034,6 +2039,7 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv) ssize_t ret; usbi_dbg("caught a fish on the hotplug pipe"); + special_event = 1; /* read the message from the hotplug thread */ ret = usbi_read(ctx->hotplug_pipe[0], &message, sizeof (message)); @@ -2061,6 +2067,7 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv) /* timerfd indicates that a timeout has expired */ int ret; usbi_dbg("timerfd triggered"); + special_event = 1; ret = handle_timerfd_trigger(ctx); if (ret < 0) { @@ -2085,6 +2092,9 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv) usbi_err(ctx, "backend handle_events failed with error %d", r); handled: + if (r == 0 && special_event) + goto redo_poll; + free(fds); return r; } diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 736c9b6..d30ecec 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 10837 +#define LIBUSB_NANO 10838 -- 1.8.3.1 ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk _______________________________________________ libusbx-devel mailing list libusbx-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libusbx-devel