summaryrefslogtreecommitdiff
path: root/libusb/hotplug.c
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2014-11-17 23:53:14 -0800
committerChris Dickens <chris.dickens@hp.com>2014-12-19 11:22:03 -0800
commit89b5407b9aa74790a64b6f32a5b14a96242ba128 (patch)
treeb8436bce0ad29d67e072e984cf0b80544c2173d1 /libusb/hotplug.c
parent3b371f1a6ab30bdebdadfcde1b96a9b98fb806ca (diff)
downloadlibusb-89b5407b9aa74790a64b6f32a5b14a96242ba128.tar.gz
core: Signal the event pipe at most one time
This change will ensure that the event pipe is only signalled at most one time during the course of any incoming events. New events that occur while the event pipe is in the signalled state will not cause the event pipe to be signalled again. This change will provide support for the use of native events on the Windows/WinCE backends, as these events are binary and do not "count" the number of times they are signalled. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Diffstat (limited to 'libusb/hotplug.c')
-rw-r--r--libusb/hotplug.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/libusb/hotplug.c b/libusb/hotplug.c
index 9171f2c..3ac159f 100644
--- a/libusb/hotplug.c
+++ b/libusb/hotplug.c
@@ -206,6 +206,7 @@ void usbi_hotplug_match(struct libusb_context *ctx, struct libusb_device *dev,
void usbi_hotplug_notification(struct libusb_context *ctx, struct libusb_device *dev,
libusb_hotplug_event event)
{
+ int pending_events;;
libusb_hotplug_message *message = calloc(1, sizeof(*message));
if (!message) {
@@ -216,12 +217,14 @@ void usbi_hotplug_notification(struct libusb_context *ctx, struct libusb_device
message->event = event;
message->device = dev;
- /* Take the event data lock and add this message to the list. */
+ /* Take the event data lock and add this message to the list.
+ * Only signal an event if there are no prior pending events. */
usbi_mutex_lock(&ctx->event_data_lock);
+ pending_events = usbi_pending_events(ctx);
list_add_tail(&message->list, &ctx->hotplug_msgs);
+ if (!pending_events)
+ usbi_signal_event(ctx);
usbi_mutex_unlock(&ctx->event_data_lock);
-
- usbi_signal_event(ctx);
}
int API_EXPORTED libusb_hotplug_register_callback(libusb_context *ctx,