core: Make event_data_lock non-recursive
authorChris Dickens <christopher.a.dickens@gmail.com>
Tue, 6 Jan 2015 18:59:01 +0000 (10:59 -0800)
committerChris Dickens <christopher.a.dickens@gmail.com>
Tue, 6 Jan 2015 18:59:01 +0000 (10:59 -0800)
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 <christopher.a.dickens@gmail.com>
libusb/core.c
libusb/io.c
libusb/libusbi.h
libusb/version_nano.h

index 698f9f5..951e85d 100644 (file)
@@ -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.
index 0e219f8..5ad883d 100644 (file)
@@ -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. */
index fc3ba19..cb86564 100644 (file)
@@ -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 */
 
index 9fa87a9..d143024 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10941
+#define LIBUSB_NANO 10942