void hash_destory(hash_table *table) { uint32_t index=0; linklist* l=NULL; int count=0; for(;index<table->size;index++) { l=table->lists[index]; if(l!=NULL) { count+=linklist_destory(l); free(l); } } free(table->lists); logInfo(LOG_NOTICE,"destroy items %d in table name:%s", count,table->name); }
/* * === FUNCTION ====================================================================== * Name: delay_table_destroy * Description: destroy delay table * ===================================================================================== */ void delay_table_destroy() { uint32_t i=0; linklist* list=NULL; linklist *msg_list=NULL; lnodeptr node=NULL; hash_node *hnode=NULL; if(table!=NULL) { logInfo(LOG_NOTICE,"destroy delayed table"); for(;i<table->size;i++) { list=table->lists[i]; node = linklist_first(list); while(node){ hnode = (hash_node *)node->data; if(hnode->data!=NULL) { msg_list=(linklist *)hnode->data; count+=linklist_destory(msg_list); free(msg_list); lDestroy++; } hnode->data=NULL; node = linklist_get_next(list,node); } } logInfo(LOG_NOTICE,"destroy msg list items:%d,free:%d,total:%d", count,fCount,mCount); logInfo(LOG_NOTICE,"create msg list:%d,delayDel:%d,destroyList:%d", lCount,delayDel,lDestroy); hash_destory(table); free(table); table=NULL; } }
static void delay_table_delete_obsolete(uint64_t key) { linklist *l = get_linklist(table,key); time_t nowtime = time(0); hash_node *hnode1=NULL; hash_node *hnode2=NULL; lnodeptr node=NULL; while(1){ node = linklist_tail(l); if(! node ){ break; } hnode1 = (hash_node *)node->data; if(hnode1->access_time+table->timeout < nowtime){ lnodeptr tail=linklist_pop_tail(l); hnode2 = (hash_node *)tail->data; if(NULL!=hnode2) { if(hnode2->data!=NULL) { linklist *msg_list=(linklist *)hnode2->data; count+=linklist_destory(msg_list); free(msg_list); hnode2->data=NULL; lDestroy++; } free(hnode2); } tail->data=NULL; free(tail); }else{ break; } } }