From 351902bbb5184ae357b16647ddd813667a4b4ce5 Mon Sep 17 00:00:00 2001 From: abhijithtk17 <142573242+abhijithtk17@users.noreply.github.com> Date: Tue, 31 Dec 2024 16:04:34 +0530 Subject: [PATCH] Add mutex for fix autoconfig renew after handle timeout reduce Author: AswiniViswanathan --- src/em/em_mgr.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/em/em_mgr.cpp b/src/em/em_mgr.cpp index 76317ae..7f713d6 100644 --- a/src/em/em_mgr.cpp +++ b/src/em/em_mgr.cpp @@ -93,7 +93,9 @@ void em_mgr_t::delete_node(em_interface_t *ruid) em->stop(); em->deinit(); - hash_map_remove(m_em_map, mac_str); + pthread_mutex_lock(&m_mutex); + hash_map_remove(m_em_map, mac_str); + pthread_mutex_unlock(&m_mutex); delete em; } @@ -130,7 +132,9 @@ em_t *em_mgr_t::create_node(em_interface_t *ruid, em_freq_band_t band, dm_easy_m } // add this em to hash map + pthread_mutex_lock(&m_mutex); hash_map_put(m_em_map, strdup(mac_str), em); + pthread_mutex_unlock(&m_mutex); printf("%s:%d: created entry for key:%s\n", __func__, __LINE__, mac_str); return em; @@ -214,7 +218,7 @@ void em_mgr_t::nodes_listener() { em_t *em = NULL; struct timeval tm; - int rc, len, highest_fd = 0; + int rc, len, highest_fd = 0, ret = 0; unsigned char buff[MAX_EM_BUFF_SZ]; em_raw_hdr_t *hdr; @@ -234,7 +238,10 @@ void em_mgr_t::nodes_listener() em = (em_t *)hash_map_get_first(m_em_map); while (em != NULL) { if (em->is_al_interface_em() == true) { - if (FD_ISSET(em->get_fd(), &m_rset)) { + pthread_mutex_lock(&m_mutex); + ret = FD_ISSET(em->get_fd(), &m_rset); + pthread_mutex_unlock(&m_mutex); + if (ret) { // receive data from this interface memset(buff, 0, MAX_EM_BUFF_SZ); len = read(em->get_fd(), buff, MAX_EM_BUFF_SZ);