diff options
author | Nikias Bassen | 2009-04-08 13:15:06 +0200 |
---|---|---|
committer | Nikias Bassen | 2009-04-08 13:15:06 +0200 |
commit | 4402ead1fcc01a75e1632be04e910359f23e9881 (patch) | |
tree | d5a87df26303ea42781c1216ec5213ed9391a8b0 | |
parent | 3aa04f1fc526d7f8d33ebafb7ab7c130350b81ed (diff) | |
download | usbmuxd-4402ead1fcc01a75e1632be04e910359f23e9881.tar.gz usbmuxd-4402ead1fcc01a75e1632be04e910359f23e9881.tar.bz2 |
Start bulk reader thread _after_ successfully creating a connection to
to prevent pthread locking with uninitialized locking variable.
Still only started once per device.
-rw-r--r-- | main.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -633,11 +633,11 @@ connect: cur_dev->use_count = 1; cur_dev->device_id = c_req->device_id; cur_dev->phone = phone; + cur_dev->bulk_reader = 0; pthread_mutex_init(&cur_dev->mutex, NULL); pthread_mutex_init(&cur_dev->writer_mutex, NULL); if (verbose >= 3) fprintf(stderr, "%s: device_use_count = %d\n", __func__, device_use_count); - pthread_create(&cur_dev->bulk_reader, NULL, usbmuxd_bulk_reader_thread, cur_dev); pthread_mutex_lock(&usbmux_mutex); device_use_list = (struct device_use_info**)realloc(device_use_list, sizeof(struct device_use_info*) * (device_use_count+1)); @@ -661,6 +661,11 @@ connect: goto leave; } + // start bulk reader thread (once per device) + if (cur_dev->bulk_reader == 0) { + pthread_create(&cur_dev->bulk_reader, NULL, usbmuxd_bulk_reader_thread, cur_dev); + } + // start connection handler thread cdata->handler_dead = 0; cdata->tag = c_req->header.tag; @@ -728,7 +733,9 @@ leave: if (verbose >= 3) fprintf(stderr, "%s: last client disconnected, cleaning up\n", __func__); cur_dev->use_count = 0; pthread_mutex_unlock(&cur_dev->mutex); - pthread_join(cur_dev->bulk_reader, NULL); + if (cur_dev->bulk_reader != 0) { + pthread_join(cur_dev->bulk_reader, NULL); + } pthread_mutex_lock(&usb_mutex); iphone_free_device(cur_dev->phone); pthread_mutex_unlock(&usb_mutex); |