summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-04-08 13:15:06 +0200
committerGravatar Nikias Bassen2009-04-08 13:15:06 +0200
commit4402ead1fcc01a75e1632be04e910359f23e9881 (patch)
treed5a87df26303ea42781c1216ec5213ed9391a8b0
parent3aa04f1fc526d7f8d33ebafb7ab7c130350b81ed (diff)
downloadusbmuxd-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.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/main.c b/main.c
index 8560aac..a75a440 100644
--- a/main.c
+++ b/main.c
@@ -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);