解决创建hash表时重复打印配置问题

This commit is contained in:
崔一鸣
2019-10-08 17:45:37 +08:00
parent 0ef167555a
commit 1b22879e90
3 changed files with 53 additions and 43 deletions

View File

@@ -261,57 +261,51 @@ static int __wrapper_MESA_htable_set_opt(MESA_htable_handle table, enum MESA_hta
return ret;
}
MESA_htable_handle kni_create_htable(const char *profile, const char *section, void *free_data_cb, void *expire_notify_cb, void *logger)
{
int mho_screen_print_ctrl;
int mho_thread_safe;
int mho_mutex_num;
int mho_hash_slot_size;
int mho_hash_max_element_num;
int mho_expire_time;
char mho_eliminate_type[KNI_SYMBOL_MAX];
MESA_load_profile_int_def(profile, section, "mho_screen_print_ctrl", &mho_screen_print_ctrl, 1);
MESA_load_profile_int_def(profile, section, "mho_thread_safe", &mho_thread_safe, 0);
MESA_load_profile_int_def(profile, section, "mho_mutex_num", &mho_mutex_num, 12);
MESA_load_profile_int_def(profile, section, "mho_hash_slot_size", &mho_hash_slot_size, 1234);
MESA_load_profile_int_def(profile, section, "mho_hash_max_element_num", &mho_hash_max_element_num, 12345);
MESA_load_profile_int_def(profile, section, "mho_expire_time", &mho_expire_time, 3600);
MESA_load_profile_string_def(profile, section, "mho_eliminate_type", mho_eliminate_type, sizeof(mho_eliminate_type), "FIFO");
void kni_get_htable_opt(struct kni_htable_opt *opt, const char *profile, const char *section, void *free_data_cb, void *expire_notify_cb, void *logger){
MESA_load_profile_int_def(profile, section, "mho_screen_print_ctrl", &(opt->mho_screen_print_ctrl), 1);
MESA_load_profile_int_def(profile, section, "mho_thread_safe", &(opt->mho_thread_safe), 0);
MESA_load_profile_int_def(profile, section, "mho_mutex_num", &(opt->mho_mutex_num), 12);
MESA_load_profile_int_def(profile, section, "mho_hash_slot_size", &(opt->mho_hash_slot_size), 1234);
MESA_load_profile_int_def(profile, section, "mho_hash_max_element_num", &(opt->mho_hash_max_element_num), 12345);
MESA_load_profile_int_def(profile, section, "mho_expire_time", &(opt->mho_expire_time), 0);
MESA_load_profile_string_def(profile, section, "mho_eliminate_type", opt->mho_eliminate_type, sizeof(opt->mho_eliminate_type), "FIFO");
KNI_LOG_ERROR(logger, "MESA_prof_load, [%s]:\n mho_screen_print_ctrl: %d\n mho_thread_safe: %d\n mho_mutex_num: %d\n"
"mho_hash_slot_size: %d\n mho_hash_max_element_num: %d\n mho_expire_time: %d\n mho_eliminate_type: %s\n", section,
mho_screen_print_ctrl, mho_thread_safe, mho_mutex_num, mho_hash_slot_size, mho_hash_max_element_num, mho_expire_time, mho_eliminate_type);
opt->mho_screen_print_ctrl, opt->mho_thread_safe, opt->mho_mutex_num, opt->mho_hash_slot_size, opt->mho_hash_max_element_num,
opt->mho_expire_time, opt->mho_eliminate_type);
opt->free_data_cb = free_data_cb;
opt->expire_notify_cb = expire_notify_cb;
}
MESA_htable_handle kni_create_htable(char *symbol, struct kni_htable_opt *opt, void *logger){
MESA_htable_handle htable = MESA_htable_born();
if(htable == NULL)
{
if(htable == NULL){
KNI_LOG_ERROR(logger, "MESA_htable: failed at MESA_htable_born");
return NULL;
}
__wrapper_MESA_htable_set_opt(htable, MHO_SCREEN_PRINT_CTRL, mho_screen_print_ctrl, logger, section);
__wrapper_MESA_htable_set_opt(htable, MHO_THREAD_SAFE, mho_thread_safe, logger, section);
__wrapper_MESA_htable_set_opt(htable, MHO_MUTEX_NUM, mho_mutex_num, logger, section);
__wrapper_MESA_htable_set_opt(htable, MHO_HASH_SLOT_SIZE, mho_hash_slot_size, logger, section);
__wrapper_MESA_htable_set_opt(htable, MHO_HASH_MAX_ELEMENT_NUM, mho_hash_max_element_num, logger, section);
__wrapper_MESA_htable_set_opt(htable, MHO_EXPIRE_TIME, mho_expire_time, logger, section);
if(strncmp(mho_eliminate_type, "LRU", KNI_SYMBOL_MAX) == 0)
{
__wrapper_MESA_htable_set_opt(htable, MHO_ELIMIMINATE_TYPE, HASH_ELIMINATE_ALGO_LRU, logger, section);
__wrapper_MESA_htable_set_opt(htable, MHO_SCREEN_PRINT_CTRL, opt->mho_screen_print_ctrl, logger, symbol);
__wrapper_MESA_htable_set_opt(htable, MHO_THREAD_SAFE, opt->mho_thread_safe, logger, symbol);
__wrapper_MESA_htable_set_opt(htable, MHO_MUTEX_NUM, opt->mho_mutex_num, logger, symbol);
__wrapper_MESA_htable_set_opt(htable, MHO_HASH_SLOT_SIZE, opt->mho_hash_slot_size, logger, symbol);
__wrapper_MESA_htable_set_opt(htable, MHO_HASH_MAX_ELEMENT_NUM, opt->mho_hash_max_element_num, logger, symbol);
__wrapper_MESA_htable_set_opt(htable, MHO_EXPIRE_TIME, opt->mho_expire_time, logger, symbol);
if(strncmp(opt->mho_eliminate_type, "LRU", KNI_SYMBOL_MAX) == 0){
__wrapper_MESA_htable_set_opt(htable, MHO_ELIMIMINATE_TYPE, HASH_ELIMINATE_ALGO_LRU, logger, symbol);
}
else
{
__wrapper_MESA_htable_set_opt(htable, MHO_ELIMIMINATE_TYPE, HASH_ELIMINATE_ALGO_FIFO, logger, section);
else{
__wrapper_MESA_htable_set_opt(htable, MHO_ELIMIMINATE_TYPE, HASH_ELIMINATE_ALGO_FIFO, logger, symbol);
}
if(free_data_cb != NULL){
if(opt->free_data_cb != NULL){
__wrapper_MESA_htable_set_opt(htable, MHO_CBFUN_DATA_FREE,
(void *)free_data_cb, sizeof(free_data_cb), logger, section);
(void *)(opt->free_data_cb), sizeof(opt->free_data_cb), logger, symbol);
}
if(expire_notify_cb != NULL){
if(opt->expire_notify_cb != NULL){
__wrapper_MESA_htable_set_opt(htable, MHO_CBFUN_DATA_EXPIRE_NOTIFY,
(void *)expire_notify_cb, sizeof(free_data_cb), logger, section);
(void *)(opt->expire_notify_cb), sizeof(opt->expire_notify_cb), logger, symbol);
}
int ret = MESA_htable_mature(htable);
if(unlikely(ret != 0))
{
KNI_LOG_ERROR(logger, "MESA_htable: failed at MESA_htable_mature, htable is %s", section);
if(unlikely(ret != 0)){
KNI_LOG_ERROR(logger, "MESA_htable: failed at MESA_htable_mature, htable is %s", symbol);
return NULL;
}
return htable;