Fix overly broad HAVE_PTHREAD_CANCEL compile guard.

Closes #1547. Thanks to Markus Gothe.
pull/1781/head
Roger A. Light 5 years ago
parent 4b100df5b1
commit b3c2ac20dc

@ -26,6 +26,7 @@ Broker:
- Fix potential memory leaks. Closes #1773. Closes #1774. - Fix potential memory leaks. Closes #1773. Closes #1774.
- Fix clients not receiving messages after a previous client with the same - Fix clients not receiving messages after a previous client with the same
client ID and positive will delay interval quit. Closes #1752. client ID and positive will delay interval quit. Closes #1752.
- Fix overly broad HAVE_PTHREAD_CANCEL compile guard. Closes #1547.
Client library: Client library:
- Improved documentation around connect callback return codes. Close #1730. - Improved documentation around connect callback return codes. Close #1730.

@ -256,7 +256,9 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
while(run){ while(run){
do{ do{
#ifdef HAVE_PTHREAD_CANCEL
pthread_testcancel(); pthread_testcancel();
#endif
rc = mosquitto_loop(mosq, timeout, max_packets); rc = mosquitto_loop(mosq, timeout, max_packets);
}while(run && rc == MOSQ_ERR_SUCCESS); }while(run && rc == MOSQ_ERR_SUCCESS);
/* Quit after fatal errors. */ /* Quit after fatal errors. */
@ -281,7 +283,9 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
return rc; return rc;
} }
do{ do{
#ifdef HAVE_PTHREAD_CANCEL
pthread_testcancel(); pthread_testcancel();
#endif
rc = MOSQ_ERR_SUCCESS; rc = MOSQ_ERR_SUCCESS;
state = mosquitto__get_state(mosq); state = mosquitto__get_state(mosq);
if(state == mosq_cs_disconnecting || state == mosq_cs_disconnected){ if(state == mosq_cs_disconnecting || state == mosq_cs_disconnected){

@ -34,7 +34,7 @@ void *mosquitto__thread_main(void *obj);
int mosquitto_loop_start(struct mosquitto *mosq) 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; if(!mosq || mosq->threaded != mosq_ts_none) return MOSQ_ERR_INVAL;
mosq->threaded = mosq_ts_self; mosq->threaded = mosq_ts_self;
@ -57,7 +57,7 @@ int mosquitto_loop_start(struct mosquitto *mosq)
int mosquitto_loop_stop(struct mosquitto *mosq, bool force) int mosquitto_loop_stop(struct mosquitto *mosq, bool force)
{ {
#if defined(WITH_THREADING) && defined(HAVE_PTHREAD_CANCEL) #if defined(WITH_THREADING)
# ifndef WITH_BROKER # ifndef WITH_BROKER
char sockpair_data = 0; char sockpair_data = 0;
# endif # endif
@ -76,9 +76,11 @@ int mosquitto_loop_stop(struct mosquitto *mosq, bool force)
#endif #endif
} }
#ifdef HAVE_PTHREAD_CANCEL
if(force){ if(force){
pthread_cancel(mosq->thread_id); pthread_cancel(mosq->thread_id);
} }
#endif
pthread_join(mosq->thread_id, NULL); pthread_join(mosq->thread_id, NULL);
mosq->thread_id = pthread_self(); mosq->thread_id = pthread_self();
mosq->threaded = mosq_ts_none; mosq->threaded = mosq_ts_none;

Loading…
Cancel
Save