获取bfd相关信息时,保护临界资源
This commit is contained in:
@@ -181,37 +181,6 @@ TEST(HEALTH_CHECK_TABLE, DELETE)
|
||||
EXPECT_TRUE(health_check_session_del(12) == -1);
|
||||
}
|
||||
|
||||
static void *bfd_get_status(void *arg)
|
||||
{
|
||||
while(1) {
|
||||
health_check_session_get_status(10);
|
||||
sleep(1);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TEST(HEALTH_CHECK_TABLE, CHECK_BFD_ENVIRONMENT)
|
||||
{
|
||||
// TEST Insert
|
||||
struct health_check policy1;
|
||||
memset(&policy1, 0, sizeof(policy1));
|
||||
policy1.method = HEALTH_CHECK_METHOD_BFD;
|
||||
snprintf(policy1.address, sizeof(policy1.address), "192.168.32.82");
|
||||
policy1.port = 65535;
|
||||
policy1.retires = 5;
|
||||
policy1.interval_ms = 300;
|
||||
EXPECT_TRUE(health_check_session_add(10, &policy1) == 0);
|
||||
|
||||
pthread_t pid1;
|
||||
pthread_create(&pid1, NULL, bfd_get_status, NULL);
|
||||
|
||||
char mac[18] = {0};
|
||||
while(1) {
|
||||
health_check_session_get_mac(10, mac);
|
||||
sleep(5);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user