获取bfd相关信息时,保护临界资源

This commit is contained in:
wangmenglan
2023-02-23 11:13:41 +08:00
parent 7acfa8d221
commit cdc3b1c589
2 changed files with 8 additions and 33 deletions

View File

@@ -166,13 +166,16 @@ int health_check_session_get_status(int session_id)
int status = 0;
struct session_iterm *tmp = NULL;
tmp = health_check_get_iterm_by_id(session_id);
pthread_rwlock_rdlock(&g_handle.rwlock);
HASH_FIND(hh1, g_handle.root_by_id, &session_id, sizeof(session_id), tmp);
if (!tmp) {
LOG_DEBUG("health check session table get status: key %d not exists", session_id);
pthread_rwlock_unlock(&g_handle.rwlock);
return -1;
}
status = tmp->is_active;
pthread_rwlock_unlock(&g_handle.rwlock);
LOG_DEBUG("health check session get status: %d", status);
return status;
}
@@ -282,14 +285,17 @@ int health_check_session_get_mac(int session_id, char *mac_buff)
uint8_t *p = NULL;
struct session_iterm *tmp = NULL;
tmp = health_check_get_iterm_by_id(session_id);
pthread_rwlock_rdlock(&g_handle.rwlock);
HASH_FIND(hh1, g_handle.root_by_id, &session_id, sizeof(session_id), tmp);
if (!tmp) {
LOG_DEBUG("health check session table get status: key %d not exists", session_id);
pthread_rwlock_unlock(&g_handle.rwlock);
return -1;
}
p = (uint8_t *)tmp->mac;
snprintf(mac_buff, 18, "%02x:%02x:%02x:%02x:%02x:%02x", p[0], p[1], p[2], p[3], p[4], p[5]);
pthread_rwlock_unlock(&g_handle.rwlock);
LOG_DEBUG("health check session get mac: %s", mac_buff);
return 0;
}