Skip to content

Commit 1e5a537

Browse files
SeppoTakalommahadevan108
authored andcommitted
net: lib: coap_client: Remove unnecessary atomic variable
In receiving thread, continuing the loops is based on has_ongoing_exchanges() so it does not need atomic coap_client_recv_active variable. When idling, it wakes from semaphore. But there was potential deadlock when coap_client_schedule_poll() would not signal the semaphore, if atomic variable was already showing that it runs. Removing the atomic variable removes this deadlock. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
1 parent 9c9dc9f commit 1e5a537

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

subsys/net/lib/coap/coap_client.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ static K_MUTEX_DEFINE(coap_client_mutex);
2424
static struct coap_client *clients[CONFIG_COAP_CLIENT_MAX_INSTANCES];
2525
static int num_clients;
2626
static K_SEM_DEFINE(coap_client_recv_sem, 0, 1);
27-
static atomic_t coap_client_recv_active;
2827

2928
static bool timeout_expired(struct coap_client_internal_request *internal_req);
3029
static void cancel_requests_with(struct coap_client *client, int error);
@@ -82,10 +81,7 @@ static int coap_client_schedule_poll(struct coap_client *client, int sock,
8281
memcpy(&internal_req->coap_request, req, sizeof(struct coap_client_request));
8382
internal_req->request_ongoing = true;
8483

85-
if (!coap_client_recv_active) {
86-
k_sem_give(&coap_client_recv_sem);
87-
}
88-
atomic_set(&coap_client_recv_active, 1);
84+
k_sem_give(&coap_client_recv_sem);
8985

9086
return 0;
9187
}
@@ -956,7 +952,6 @@ static void cancel_requests_with(struct coap_client *client, int error)
956952
reset_internal_request(&client->requests[i]);
957953
}
958954
}
959-
atomic_clear(&coap_client_recv_active);
960955
k_mutex_unlock(&client->lock);
961956

962957
}
@@ -974,7 +969,6 @@ void coap_client_recv(void *coap_cl, void *a, void *b)
974969

975970
k_sem_take(&coap_client_recv_sem, K_FOREVER);
976971
while (true) {
977-
atomic_set(&coap_client_recv_active, 1);
978972
ret = handle_poll();
979973
if (ret < 0) {
980974
/* Error in polling */
@@ -987,7 +981,6 @@ void coap_client_recv(void *coap_cl, void *a, void *b)
987981
continue;
988982
} else {
989983
idle:
990-
atomic_set(&coap_client_recv_active, 0);
991984
k_sem_take(&coap_client_recv_sem, K_FOREVER);
992985
}
993986
}

0 commit comments

Comments
 (0)