Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double lock of lockRecv. #398

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading