dns_cache: Replace cache timeout mechanism with time wheel algorithm to reduce CPU usage

This commit is contained in:
Nick Peng
2023-09-23 23:31:19 +08:00
parent b7fb501be9
commit bfacad33ae
10 changed files with 760 additions and 356 deletions

50
src/include/timer_wheel.h Normal file
View File

@@ -0,0 +1,50 @@
/*************************************************************************
*
* Copyright (C) 2018-2023 Ruilin Peng (Nick) <pymumu@gmail.com>.
*
* smartdns is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* smartdns is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __TIMER_WHEEL_H
#define __TIMER_WHEEL_H
#include "list.h"
struct tw_base;
struct tw_timer_list;
typedef void (*tw_func)(struct tw_timer_list *, void *, unsigned long);
typedef void (*tw_del_func)(struct tw_timer_list *, void *);
struct tw_timer_list {
void *data;
unsigned long expires;
tw_func function;
tw_del_func del_function;
struct list_head entry;
};
struct tw_base *tw_init_timers(void);
int tw_cleanup_timers(struct tw_base *);
void tw_add_timer(struct tw_base *, struct tw_timer_list *);
int tw_del_timer(struct tw_base *, struct tw_timer_list *);
int tw_mod_timer_pending(struct tw_base *, struct tw_timer_list *, unsigned long);
int tw_mod_timer(struct tw_base *, struct tw_timer_list *, unsigned long);
#endif