Skip to content

Commit

Permalink
Possible patch for POSIX conditional wait issue. ZD 16769
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske committed Sep 29, 2023
1 parent 28dffb5 commit 42b4509
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,31 @@ static int MqttClient_Publish_ReadPayload(MqttClient* client,
}
#elif defined(WOLFMQTT_POSIX_SEMAPHORES)
/* Posix style semaphore */
int wm_SemInit(wm_Sem *s){
int wm_SemInit(wm_Sem *s) {
s->lockCount = 0;
pthread_mutex_init(&s->mutex, NULL);
pthread_cond_init(&s->cond, NULL);
return 0;
}
int wm_SemFree(wm_Sem *s){
int wm_SemFree(wm_Sem *s) {
pthread_mutex_destroy(&s->mutex);
pthread_cond_destroy(&s->cond);
return 0;
}
int wm_SemLock(wm_Sem *s){
int wm_SemLock(wm_Sem *s) {
pthread_mutex_lock(&s->mutex);
while (s->lockCount > 0)
pthread_cond_wait(&s->cond, &s->mutex);
s->lockCount++;
pthread_mutex_unlock(&s->mutex);
return 0;
}
int wm_SemUnlock(wm_Sem *s){
int wm_SemUnlock(wm_Sem *s) {
pthread_mutex_lock(&s->mutex);
s->lockCount--;
pthread_cond_signal(&s->cond);
if (s->lockCount > 0) {
s->lockCount--;
pthread_cond_signal(&s->cond);
}
pthread_mutex_unlock(&s->mutex);
return 0;
}
Expand Down

0 comments on commit 42b4509

Please sign in to comment.