summaryrefslogtreecommitdiff
path: root/libusb/libusbi.h
diff options
context:
space:
mode:
authorDaniel Drake <dsd@gentoo.org>2008-11-20 15:31:10 +0000
committerDaniel Drake <dsd@gentoo.org>2008-11-21 10:44:34 +0000
commitc32aa662769b676ff3247778664fccc71fc427ec (patch)
treed3c27ca15790286996169038b27ce3116d401627 /libusb/libusbi.h
parent1d7cf3d0fa8698eae25097cbda1870be90ff6f5e (diff)
downloadlibusb-c32aa662769b676ff3247778664fccc71fc427ec.tar.gz
Pause event handling while opening and closing devices
Ludovic Rousseau found that crashes often occur if you close a device while another thread is doing event handling. Fix this by adding an internal control pipe, which the close routines use to interrupt the event handler and obtain the event handling lock, ensuring that no other thread is handling events while the device is closed. After the close completes, it signals all the event handlers to start up again using the usual mechanism. Also modified libusb_open() to do a similar thing, so that event handlers are interrupted in order to realise that a new poll fd has appeared.
Diffstat (limited to 'libusb/libusbi.h')
-rw-r--r--libusb/libusbi.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index 43dd109..b51ba0b 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -144,6 +144,10 @@ struct libusb_context {
int debug;
int debug_fixed;
+ /* internal control pipe, used for interrupting event handling when
+ * something needs to modify poll fds. */
+ int ctrl_pipe[2];
+
struct list_head usb_devs;
pthread_mutex_t usb_devs_lock;
@@ -159,10 +163,15 @@ struct libusb_context {
struct list_head flying_transfers;
pthread_mutex_t flying_transfers_lock;
- /* list of poll fd's */
+ /* list of poll fds */
struct list_head pollfds;
pthread_mutex_t pollfds_lock;
+ /* a counter that is set when we want to interrupt event handling, in order
+ * to modify the poll fd set. and a lock to protect it. */
+ unsigned int pollfd_modify;
+ pthread_mutex_t pollfd_modify_lock;
+
/* user callbacks for pollfd changes */
libusb_pollfd_added_cb fd_added_cb;
libusb_pollfd_removed_cb fd_removed_cb;
@@ -255,7 +264,8 @@ struct usb_descriptor_header {
/* shared data and functions */
-void usbi_io_init(struct libusb_context *ctx);
+int usbi_io_init(struct libusb_context *ctx);
+void usbi_io_exit(struct libusb_context *ctx);
struct libusb_device *usbi_alloc_device(struct libusb_context *ctx,
unsigned long session_id);