summaryrefslogtreecommitdiffstats
path: root/libusbmuxd
diff options
context:
space:
mode:
Diffstat (limited to 'libusbmuxd')
-rw-r--r--libusbmuxd/libusbmuxd.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/libusbmuxd/libusbmuxd.c b/libusbmuxd/libusbmuxd.c
index 8470ddc..952e680 100644
--- a/libusbmuxd/libusbmuxd.c
+++ b/libusbmuxd/libusbmuxd.c
@@ -650,6 +650,7 @@ static void *device_monitor(void *data)
int usbmuxd_init()
{
int res = 0;
+ LOCK;
handle_events = 1;
#ifdef WIN32
devmon = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)device_monitor, NULL, 0, NULL);
@@ -662,16 +663,19 @@ int usbmuxd_init()
if (res != 0) {
DEBUG(1, "%s: ERROR: Could not start device watcher thread!\n", __func__);
handle_events = 0;
+ UNLOCK;
return res;
}
struct timespec ts = {0, 250000000};
nanosleep(&ts, NULL);
libusbmuxd_initialized = 1;
+ UNLOCK;
return 0;
}
int usbmuxd_deinit()
{
+ LOCK;
handle_events = 0;
shutdown_socket(listenfd, SHUT_RDWR);
@@ -687,6 +691,7 @@ int usbmuxd_deinit()
}
#endif
libusbmuxd_initialized = 0;
+ UNLOCK;
return 0;
}
@@ -698,7 +703,12 @@ int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data)
event_cb = callback;
event_user_data = user_data;
- if (!libusbmuxd_initialized) {
+ int is_initialized = 0;
+ LOCK;
+ is_initialized = libusbmuxd_initialized;
+ UNLOCK;
+
+ if (!is_initialized) {
usbmuxd_init();
} else {
FOREACH(usbmuxd_device_info_t *dev, &devices) {
@@ -860,7 +870,12 @@ int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device)
return -EINVAL;
}
- if (!libusbmuxd_initialized) {
+ int is_initialized = 0;
+ LOCK;
+ is_initialized = libusbmuxd_initialized;
+ UNLOCK;
+
+ if (!is_initialized) {
usbmuxd_init();
}