diff options
author | Nikias Bassen | 2013-04-19 19:20:51 +0200 |
---|---|---|
committer | Nikias Bassen | 2013-04-19 19:20:51 +0200 |
commit | 3969b90cdeabe09028266c8b3a28c9ffcec82cec (patch) | |
tree | 89a571ca1d45ac3a81e70ef1b8bc57907facc541 /libusbmuxd | |
parent | 8bfe1c0e7f59325092edf16c1e66f86a1a02feff (diff) | |
download | usbmuxd-3969b90cdeabe09028266c8b3a28c9ffcec82cec.tar.gz usbmuxd-3969b90cdeabe09028266c8b3a28c9ffcec82cec.tar.bz2 |
libusbmuxd: use separate mutex for initialization
Diffstat (limited to 'libusbmuxd')
-rw-r--r-- | libusbmuxd/libusbmuxd.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/libusbmuxd/libusbmuxd.c b/libusbmuxd/libusbmuxd.c index 904f1ed..6721fe6 100644 --- a/libusbmuxd/libusbmuxd.c +++ b/libusbmuxd/libusbmuxd.c @@ -79,6 +79,7 @@ static void* event_user_data = NULL; static thread_t devmon = NULL; static mutex_t mutex; +static mutex_t init_mutex; static int listenfd = -1; @@ -87,12 +88,14 @@ static int proto_version = 0; static __attribute__((constructor)) void libusbmuxd_library_init() { + mutex_init(&init_mutex); mutex_init(&mutex); } static __attribute__((destructor)) void libusbmuxd_library_deinit() { mutex_destroy(&mutex); + mutex_destroy(&init_mutex); } /** @@ -653,25 +656,25 @@ static void *device_monitor(void *data) int usbmuxd_init() { int res = 0; - mutex_lock(&mutex); + mutex_lock(&init_mutex); handle_events = 1; res = thread_create(&devmon, device_monitor, NULL); if (res != 0) { DEBUG(1, "%s: ERROR: Could not start device watcher thread!\n", __func__); handle_events = 0; - mutex_unlock(&mutex); + mutex_unlock(&init_mutex); return res; } struct timespec ts = {0, 250000000}; nanosleep(&ts, NULL); libusbmuxd_initialized = 1; - mutex_unlock(&mutex); + mutex_unlock(&init_mutex); return 0; } int usbmuxd_deinit() { - mutex_lock(&mutex); + mutex_lock(&init_mutex); handle_events = 0; shutdown_socket(listenfd, SHUT_RDWR); @@ -681,7 +684,7 @@ int usbmuxd_deinit() thread_join(devmon); } libusbmuxd_initialized = 0; - mutex_unlock(&mutex); + mutex_unlock(&init_mutex); return 0; } @@ -694,9 +697,9 @@ int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data) event_user_data = user_data; int is_initialized = 0; - mutex_lock(&mutex); + mutex_lock(&init_mutex); is_initialized = libusbmuxd_initialized; - mutex_unlock(&mutex); + mutex_unlock(&init_mutex); if (!is_initialized) { usbmuxd_init(); @@ -861,9 +864,9 @@ int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device) } int is_initialized = 0; - mutex_lock(&mutex); + mutex_lock(&init_mutex); is_initialized = libusbmuxd_initialized; - mutex_unlock(&mutex); + mutex_unlock(&init_mutex); if (!is_initialized) { usbmuxd_init(); |