Skip to content

Commit

Permalink
Fix overly broad HAVE_PTHREAD_CANCEL compile guard.
Browse files Browse the repository at this point in the history
Closes #1547. Thanks to Markus Gothe.
  • Loading branch information
ralight committed Aug 11, 2020
1 parent 4b100df commit b3c2ac2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog.txt
Expand Up @@ -26,6 +26,7 @@ Broker:
- Fix potential memory leaks. Closes #1773. Closes #1774.
- Fix clients not receiving messages after a previous client with the same
client ID and positive will delay interval quit. Closes #1752.
- Fix overly broad HAVE_PTHREAD_CANCEL compile guard. Closes #1547.

Client library:
- Improved documentation around connect callback return codes. Close #1730.
Expand Down
4 changes: 4 additions & 0 deletions lib/loop.c
Expand Up @@ -256,7 +256,9 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)

while(run){
do{
#ifdef HAVE_PTHREAD_CANCEL
pthread_testcancel();
#endif
rc = mosquitto_loop(mosq, timeout, max_packets);
}while(run && rc == MOSQ_ERR_SUCCESS);
/* Quit after fatal errors. */
Expand All @@ -281,7 +283,9 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
return rc;
}
do{
#ifdef HAVE_PTHREAD_CANCEL
pthread_testcancel();
#endif
rc = MOSQ_ERR_SUCCESS;
state = mosquitto__get_state(mosq);
if(state == mosq_cs_disconnecting || state == mosq_cs_disconnected){
Expand Down
6 changes: 4 additions & 2 deletions lib/thread_mosq.c
Expand Up @@ -34,7 +34,7 @@ void *mosquitto__thread_main(void *obj);

int mosquitto_loop_start(struct mosquitto *mosq)
{
#if defined(WITH_THREADING) && defined(HAVE_PTHREAD_CANCEL)
#if defined(WITH_THREADING)
if(!mosq || mosq->threaded != mosq_ts_none) return MOSQ_ERR_INVAL;

mosq->threaded = mosq_ts_self;
Expand All @@ -57,7 +57,7 @@ int mosquitto_loop_start(struct mosquitto *mosq)

int mosquitto_loop_stop(struct mosquitto *mosq, bool force)
{
#if defined(WITH_THREADING) && defined(HAVE_PTHREAD_CANCEL)
#if defined(WITH_THREADING)
# ifndef WITH_BROKER
char sockpair_data = 0;
# endif
Expand All @@ -76,9 +76,11 @@ int mosquitto_loop_stop(struct mosquitto *mosq, bool force)
#endif
}

#ifdef HAVE_PTHREAD_CANCEL
if(force){
pthread_cancel(mosq->thread_id);
}
#endif
pthread_join(mosq->thread_id, NULL);
mosq->thread_id = pthread_self();
mosq->threaded = mosq_ts_none;
Expand Down

0 comments on commit b3c2ac2

Please sign in to comment.