From 82e5f5764422393eff28aaa8ed35b3ea3db74490 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Fri, 27 Dec 2013 01:55:08 +0100 Subject: preflight: replace idevice_event_* with thread safe implementation idevice_event_subscribe() calls usbmuxd_subscribe() which will start a thread waiting for device add/remove events. But this implementation is not able to handle more than one "subscription". However the preflight worker will start a thread for _each_ device resulting in a really messed up situation if more than one device is attached at the same time. This fix will use usbmuxd's internal device_remove function calling a preflight callback to make this implementation thread safe. --- src/device.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/device.c') diff --git a/src/device.c b/src/device.c index b6cc32a..1e3cc83 100644 --- a/src/device.c +++ b/src/device.c @@ -112,6 +112,7 @@ struct mux_device uint16_t next_sport; unsigned char *pktbuf; uint32_t pktlen; + void *preflight_cb_data; }; static struct collection device_list; @@ -648,6 +649,7 @@ int device_add(struct usb_device *usbdev) dev->next_sport = 1; dev->pktbuf = malloc(DEV_MRU); dev->pktlen = 0; + dev->preflight_cb_data = NULL; struct version_header vh; vh.major = htonl(1); vh.minor = htonl(0); @@ -674,6 +676,9 @@ void device_remove(struct usb_device *usbdev) client_device_remove(dev->id); collection_free(&dev->connections); } + if (dev->preflight_cb_data) { + preflight_device_remove_cb(dev->preflight_cb_data); + } collection_remove(&device_list, dev); free(dev->pktbuf); free(dev); @@ -690,7 +695,17 @@ void device_set_visible(int device_id) dev->visible = 1; break; } - } ENDFOREACH + } ENDFOREACH +} + +void device_set_preflight_cb_data(int device_id, void* data) +{ + FOREACH(struct mux_device *dev, &device_list) { + if(dev->id == device_id) { + dev->preflight_cb_data = data; + break; + } + } ENDFOREACH } int device_get_count(int include_hidden) -- cgit v1.1-32-gdbae