From 5e8928b8ca40b1dd33956c807a9bf745b7999852 Mon Sep 17 00:00:00 2001 From: Chris Dickens Date: Tue, 6 Jan 2015 10:59:01 -0800 Subject: [PATCH] core: Make event_data_lock non-recursive Hans pointed out that usbi_fd_notification() is only used by the functions that add/remove pollfds. They already hold the required lock, so to make it less expensive we will assume the lock is already held. The usbi_fd_notification() function has also been moved from core.c into io.c and made static, since it now only has one use case. Signed-off-by: Chris Dickens --- libusb/core.c | 18 ------------------ libusb/io.c | 18 +++++++++++++++++- libusb/libusbi.h | 1 - libusb/version_nano.h | 2 +- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/libusb/core.c b/libusb/core.c index 698f9f5..951e85d 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -1194,24 +1194,6 @@ int usbi_clear_event(struct libusb_context *ctx) return 0; } -/* - * Interrupt the iteration of the event handling thread, so that it picks - * up the fd change. - */ -void usbi_fd_notification(struct libusb_context *ctx) -{ - int pending_events; - - /* Record that there is a new poll fd. - * Only signal an event if there are no prior pending events. */ - usbi_mutex_lock(&ctx->event_data_lock); - pending_events = usbi_pending_events(ctx); - ctx->pollfds_modified = 1; - if (!pending_events) - usbi_signal_event(ctx); - usbi_mutex_unlock(&ctx->event_data_lock); -} - /** \ingroup dev * Open a device and obtain a device handle. A handle allows you to perform * I/O on the device in question. diff --git a/libusb/io.c b/libusb/io.c index 0e219f8..5ad883d 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -1114,7 +1114,7 @@ int usbi_io_init(struct libusb_context *ctx) usbi_mutex_init_recursive(&ctx->events_lock, NULL); usbi_mutex_init(&ctx->event_waiters_lock, NULL); usbi_cond_init(&ctx->event_waiters_cond, NULL); - usbi_mutex_init_recursive(&ctx->event_data_lock, NULL); + usbi_mutex_init(&ctx->event_data_lock, NULL); list_init(&ctx->flying_transfers); list_init(&ctx->ipollfds); list_init(&ctx->hotplug_msgs); @@ -2468,6 +2468,22 @@ void API_EXPORTED libusb_set_pollfd_notifiers(libusb_context *ctx, ctx->fd_cb_user_data = user_data; } +/* + * Interrupt the iteration of the event handling thread, so that it picks + * up the fd change. Callers of this function must hold the event_data_lock. + */ +static void usbi_fd_notification(struct libusb_context *ctx) +{ + int pending_events; + + /* Record that there is a new poll fd. + * Only signal an event if there are no prior pending events. */ + pending_events = usbi_pending_events(ctx); + ctx->pollfds_modified = 1; + if (!pending_events) + usbi_signal_event(ctx); +} + /* Add a file descriptor to the list of file descriptors to be monitored. * events should be specified as a bitmask of events passed to poll(), e.g. * POLLIN and/or POLLOUT. */ diff --git a/libusb/libusbi.h b/libusb/libusbi.h index fc3ba19..cb86564 100644 --- a/libusb/libusbi.h +++ b/libusb/libusbi.h @@ -500,7 +500,6 @@ struct usbi_pollfd { int usbi_add_pollfd(struct libusb_context *ctx, int fd, short events); void usbi_remove_pollfd(struct libusb_context *ctx, int fd); -void usbi_fd_notification(struct libusb_context *ctx); /* device discovery */ diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 9fa87a9..d143024 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 10941 +#define LIBUSB_NANO 10942 -- 2.7.4