From 097045176261d2a706359120b1ba4ba53310a193 Mon Sep 17 00:00:00 2001 From: Daniel d'Andrada Date: Thu, 6 Jun 2019 15:04:14 +0200 Subject: [PATCH] pthread_cancel() is not available on Android Thus mosquitto_loop_start() and mosquitto_loop_stop() won't be available there (and mosquitto_connect_async() as a consequence). Signed-off-by: Daniel d'Andrada --- config.h | 5 +++++ lib/mosquitto.c | 2 ++ lib/thread_mosq.c | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/config.h b/config.h index b7a7616dda..4fd2ae4def 100644 --- a/config.h +++ b/config.h @@ -60,4 +60,9 @@ #define UNUSED(A) (void)(A) +/* Android Bionic libpthread implementation doesn't have pthread_cancel */ +#ifndef ANDROID +# define HAVE_PTHREAD_CANCEL +#endif + #endif diff --git a/lib/mosquitto.c b/lib/mosquitto.c index ed71604dcd..4b5768f38b 100644 --- a/lib/mosquitto.c +++ b/lib/mosquitto.c @@ -201,11 +201,13 @@ void mosquitto__destroy(struct mosquitto *mosq) if(!mosq) return; #ifdef WITH_THREADING +# ifdef HAVE_PTHREAD_CANCEL if(mosq->threaded == mosq_ts_self && !pthread_equal(mosq->thread_id, pthread_self())){ pthread_cancel(mosq->thread_id); pthread_join(mosq->thread_id, NULL); mosq->threaded = mosq_ts_none; } +# endif if(mosq->id){ /* If mosq->id is not NULL then the client has already been initialised diff --git a/lib/thread_mosq.c b/lib/thread_mosq.c index 39f6e353a3..7bde453d3d 100644 --- a/lib/thread_mosq.c +++ b/lib/thread_mosq.c @@ -27,7 +27,7 @@ void *mosquitto__thread_main(void *obj); int mosquitto_loop_start(struct mosquitto *mosq) { -#ifdef WITH_THREADING +#if defined(WITH_THREADING) && defined(HAVE_PTHREAD_CANCEL) if(!mosq || mosq->threaded != mosq_ts_none) return MOSQ_ERR_INVAL; mosq->threaded = mosq_ts_self; @@ -43,7 +43,7 @@ int mosquitto_loop_start(struct mosquitto *mosq) int mosquitto_loop_stop(struct mosquitto *mosq, bool force) { -#ifdef WITH_THREADING +#if defined(WITH_THREADING) && defined(HAVE_PTHREAD_CANCEL) # ifndef WITH_BROKER char sockpair_data = 0; # endif