Skip to content

Commit

Permalink
Merge pull request #398 from philljj/fix_threading_errors
Browse files Browse the repository at this point in the history
Fix double lock of lockRecv.
  • Loading branch information
embhorn authored Mar 22, 2024
2 parents 9bc9856 + 57805f8 commit f9651ab
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ static int MqttClient_CancelMessage(MqttClient *client, MqttObject* msg);
s->sem = NULL;
return 0;
}

int wm_SemLock(wm_Sem *s) {
dispatch_semaphore_wait(s->sem, DISPATCH_TIME_FOREVER);
return 0;
Expand Down Expand Up @@ -275,11 +274,14 @@ static int MqttReadStart(MqttClient* client, MqttMsgStat* stat)
{
int rc = MQTT_CODE_SUCCESS;

#ifdef WOLFMQTT_DEBUG_CLIENT
#if defined(WOLFMQTT_DEBUG_CLIENT) || !defined(WOLFMQTT_ALLOW_NODATA_UNLOCK)
#ifdef WOLFMQTT_DEBUG_CLIENT
if (stat->isReadActive) {
MQTT_TRACE_MSG("Warning, recv already locked!");
rc = MQTT_CODE_ERROR_SYSTEM;
}
#endif /* WOLFMQTT_DEBUG_CLIENT */
#ifndef WOLFMQTT_ALLOW_NODATA_UNLOCK
/* detect if a read is already in progress */
#ifdef WOLFMQTT_MULTITHREAD
if (wm_SemLock(&client->lockClient) == 0)
Expand All @@ -293,9 +295,11 @@ static int MqttReadStart(MqttClient* client, MqttMsgStat* stat)
wm_SemUnlock(&client->lockClient);
#endif
}
if (rc != 0)
#endif /* WOLFMQTT_ALLOW_NODATA_UNLOCK */
if (rc != MQTT_CODE_SUCCESS) {
return rc;
#endif /* WOLFMQTT_DEBUG_CLIENT */
}
#endif /* WOLFMQTT_DEBUG_CLIENT || !WOLFMQTT_ALLOW_NODATA_UNLOCK */

#ifdef WOLFMQTT_MULTITHREAD
rc = wm_SemLock(&client->lockRecv);
Expand Down

0 comments on commit f9651ab

Please sign in to comment.