# HG changeset patch # User Edouard Tisserant # Date 1721297126 -7200 # Node ID 78f9abfb32a0886bab211a5471b46aeed6f9b3e3 # Parent 056657cd14848f9ba1195546149e742475dd7e5c MQTT: Stop publish thread properly on PLC stop diff -r 056657cd1484 -r 78f9abfb32a0 mqtt/mqtt_client_gen.py --- a/mqtt/mqtt_client_gen.py Thu Jul 18 11:42:08 2024 +0200 +++ b/mqtt/mqtt_client_gen.py Thu Jul 18 12:05:26 2024 +0200 @@ -393,7 +393,14 @@ {{ int rc; - /* TODO stop publish thread */ + /* stop publish thread */ + MQTT_stop_thread = 1; + if (pthread_mutex_trylock(&MQTT_mutex) == 0){{ + /* unblock publish thread so that it can stop normally */ + pthread_cond_signal(&MQTT_new_data); + pthread_mutex_unlock(&MQTT_mutex); + }} + pthread_join(publishThread, NULL); #ifdef USE_MQTT_5 if (rc = MQTTClient_disconnect5(client, 5000, MQTTREASONCODE_SUCCESS, NULL) != MQTTCLIENT_SUCCESS) @@ -539,6 +546,8 @@ }} pthread_mutex_unlock(&MQTT_mutex); + + if(MQTT_stop_thread) break; }} if(!MQTT_stop_thread){{