Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No pthread_cancel() on Android #1308

Merged
merged 1 commit into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions lib/mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/thread_mosq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down