summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2019-05-25 17:58:17 +0200
committerGravatar Nikias Bassen2019-05-25 17:58:17 +0200
commit5304a31704e5ddc9eeefe905f05b5f6938f9c646 (patch)
tree3a521189255e20d608007c0a09ebb78b142c1d93
parent7b2b09fe7f4bd20cba4dae3e9104970c94618da5 (diff)
downloadlibusbmuxd-5304a31704e5ddc9eeefe905f05b5f6938f9c646.tar.gz
libusbmuxd-5304a31704e5ddc9eeefe905f05b5f6938f9c646.tar.bz2
Make sure device monitor thread can be cancelled without pthread_cancel
-rw-r--r--common/thread.c4
-rw-r--r--src/libusbmuxd.c8
2 files changed, 7 insertions, 5 deletions
diff --git a/common/thread.c b/common/thread.c
index da7eb21..eb535ab 100644
--- a/common/thread.c
+++ b/common/thread.c
@@ -77,12 +77,12 @@ int thread_alive(THREAD_T thread)
int thread_cancel(THREAD_T thread)
{
#ifdef WIN32
- return 0;
+ return -1;
#else
#ifdef HAVE_PTHREAD_CANCEL
return pthread_cancel(thread);
#else
- return 0;
+ return -1;
#endif
#endif
}
diff --git a/src/libusbmuxd.c b/src/libusbmuxd.c
index d971f14..40eefea 100644
--- a/src/libusbmuxd.c
+++ b/src/libusbmuxd.c
@@ -117,6 +117,7 @@ static int libusbmuxd_debug = 0;
static struct collection devices;
static THREAD_T devmon = THREAD_T_NULL;
static int listenfd = -1;
+static int running = 0;
static int cancelling = 0;
static volatile int use_tag = 0;
@@ -858,7 +859,6 @@ static int usbmuxd_listen_poll()
#ifdef HAVE_INOTIFY
static int use_inotify = 1;
-
static int usbmuxd_listen_inotify()
{
int inot_fd;
@@ -1057,7 +1057,7 @@ static void device_monitor_cleanup(void* data)
*/
static void *device_monitor(void *data)
{
- int running = 1;
+ running = 1;
collection_init(&devices);
cancelling = 0;
@@ -1173,7 +1173,9 @@ USBMUXD_API int usbmuxd_events_unsubscribe(usbmuxd_subscription_context_t ctx)
cancelling = 1;
socket_shutdown(listenfd, SHUT_RDWR);
if (thread_alive(devmon)) {
- thread_cancel(devmon);
+ if (thread_cancel(devmon) < 0) {
+ running = 0;
+ }
res = thread_join(devmon);
thread_free(devmon);
devmon = THREAD_T_NULL;