Commit adaada7f authored by Ian Craggs's avatar Ian Craggs

Fix for bug #408070 - high CPU use after connection lost

parent 1abca940
...@@ -543,7 +543,7 @@ thread_return_type WINAPI MQTTClient_run(void* n) ...@@ -543,7 +543,7 @@ thread_return_type WINAPI MQTTClient_run(void* n)
} }
} }
run_id = 0; run_id = 0;
running = 0; running = tostop = 0;
Thread_unlock_mutex(mqttclient_mutex); Thread_unlock_mutex(mqttclient_mutex);
FUNC_EXIT; FUNC_EXIT;
return 0; return 0;
...@@ -555,7 +555,7 @@ void MQTTClient_stop() ...@@ -555,7 +555,7 @@ void MQTTClient_stop()
int rc = 0; int rc = 0;
FUNC_ENTRY; FUNC_ENTRY;
if (running == 1 && tostop == 0 && Thread_getid() != run_id) if (running == 1 && tostop == 0)
{ {
int conn_count = 0; int conn_count = 0;
ListElement* current = NULL; ListElement* current = NULL;
...@@ -576,6 +576,8 @@ void MQTTClient_stop() ...@@ -576,6 +576,8 @@ void MQTTClient_stop()
{ {
int count = 0; int count = 0;
tostop = 1; tostop = 1;
if (Thread_getid() != run_id)
{
while (running && ++count < 100) while (running && ++count < 100)
{ {
Thread_unlock_mutex(mqttclient_mutex); Thread_unlock_mutex(mqttclient_mutex);
...@@ -583,8 +585,8 @@ void MQTTClient_stop() ...@@ -583,8 +585,8 @@ void MQTTClient_stop()
MQTTClient_sleep(100L); MQTTClient_sleep(100L);
Thread_lock_mutex(mqttclient_mutex); Thread_lock_mutex(mqttclient_mutex);
} }
}
rc = 1; rc = 1;
tostop = 0;
} }
} }
FUNC_EXIT_RC(rc); FUNC_EXIT_RC(rc);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment