diff options
Diffstat (limited to 'libusb/io.c')
-rw-r--r-- | libusb/io.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/libusb/io.c b/libusb/io.c index 8c2b02a..6051d7f 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -2081,9 +2081,16 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv) /* prevent attempts to recursively handle events (e.g. calling into * libusb_handle_events() from within a hotplug or transfer callback) */ + usbi_mutex_lock(&ctx->event_data_lock); + r = 0; if (usbi_handling_events(ctx)) - return LIBUSB_ERROR_BUSY; - usbi_start_event_handling(ctx); + r = LIBUSB_ERROR_BUSY; + else + usbi_start_event_handling(ctx); + usbi_mutex_unlock(&ctx->event_data_lock); + + if (r) + return r; /* there are certain fds that libusb uses internally, currently: * |