dns-client: Fix issue that bootstrap dns not working caused by reducing CPU usage
This commit is contained in:
@@ -186,6 +186,7 @@ struct dns_client {
|
|||||||
/* query list */
|
/* query list */
|
||||||
struct list_head dns_request_list;
|
struct list_head dns_request_list;
|
||||||
pthread_cond_t run_cond;
|
pthread_cond_t run_cond;
|
||||||
|
atomic_t run_period;
|
||||||
atomic_t dns_server_num;
|
atomic_t dns_server_num;
|
||||||
|
|
||||||
/* ECS */
|
/* ECS */
|
||||||
@@ -1312,7 +1313,12 @@ static int _dns_client_server_pending(char *server_ip, int port, dns_server_type
|
|||||||
|
|
||||||
pthread_mutex_lock(&pending_server_mutex);
|
pthread_mutex_lock(&pending_server_mutex);
|
||||||
list_add_tail(&pending->list, &pending_servers);
|
list_add_tail(&pending->list, &pending_servers);
|
||||||
|
atomic_set(&client.run_period, 1);
|
||||||
pthread_mutex_unlock(&pending_server_mutex);
|
pthread_mutex_unlock(&pending_server_mutex);
|
||||||
|
|
||||||
|
pthread_mutex_lock(&client.domain_map_lock);
|
||||||
|
pthread_cond_signal(&client.run_cond);
|
||||||
|
pthread_mutex_unlock(&client.domain_map_lock);
|
||||||
return 0;
|
return 0;
|
||||||
errout:
|
errout:
|
||||||
if (pending) {
|
if (pending) {
|
||||||
@@ -3266,6 +3272,12 @@ static void _dns_client_add_pending_servers(void)
|
|||||||
dely = 0;
|
dely = 0;
|
||||||
|
|
||||||
pthread_mutex_lock(&pending_server_mutex);
|
pthread_mutex_lock(&pending_server_mutex);
|
||||||
|
if (list_empty(&pending_servers)) {
|
||||||
|
atomic_set(&client.run_period, 0);
|
||||||
|
} else {
|
||||||
|
atomic_set(&client.run_period, 1);
|
||||||
|
}
|
||||||
|
|
||||||
list_for_each_entry_safe(pending, tmp, &pending_servers, list)
|
list_for_each_entry_safe(pending, tmp, &pending_servers, list)
|
||||||
{
|
{
|
||||||
list_add(&pending->retry_list, &retry_list);
|
list_add(&pending->retry_list, &retry_list);
|
||||||
@@ -3436,7 +3448,7 @@ static void *_dns_client_work(void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&client.domain_map_lock);
|
pthread_mutex_lock(&client.domain_map_lock);
|
||||||
if (list_empty(&client.dns_request_list)) {
|
if (list_empty(&client.dns_request_list) && atomic_read(&client.run_period) == 0) {
|
||||||
pthread_cond_wait(&client.run_cond, &client.domain_map_lock);
|
pthread_cond_wait(&client.run_cond, &client.domain_map_lock);
|
||||||
expect_time = get_tick_count();
|
expect_time = get_tick_count();
|
||||||
pthread_mutex_unlock(&client.domain_map_lock);
|
pthread_mutex_unlock(&client.domain_map_lock);
|
||||||
@@ -3519,6 +3531,7 @@ int dns_client_init(void)
|
|||||||
memset(&client, 0, sizeof(client));
|
memset(&client, 0, sizeof(client));
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
atomic_set(&client.dns_server_num, 0);
|
atomic_set(&client.dns_server_num, 0);
|
||||||
|
atomic_set(&client.run_period, 0);
|
||||||
|
|
||||||
epollfd = epoll_create1(EPOLL_CLOEXEC);
|
epollfd = epoll_create1(EPOLL_CLOEXEC);
|
||||||
if (epollfd < 0) {
|
if (epollfd < 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user