void cleanup_hitcache(void) { CACHE_HIT *cachehit; node *i,*i_next; struct timeb now; int32_t gone; int32_t timeout = (cfg.max_hitcache_time + (cfg.max_hitcache_time / 2))*1000; //1,5 pthread_rwlock_wrlock(&hitcache_lock); i = get_first_node_list(&ll_hitcache); while (i) { i_next = i->next; cachehit = get_data_from_node(i); cs_ftime(&now); gone = comp_timeb(&now, &cachehit->time); if(cachehit && gone>timeout){ remove_elem_list(&ll_hitcache, &cachehit->ll_node); remove_elem_hash_table(&ht_hitcache, &cachehit->ht_node); NULLFREE(cachehit); } i = i_next; } pthread_rwlock_unlock(&hitcache_lock); }
void cacheex_cleanup_hitcache(bool force) { CACHE_HIT *cachehit; node *i,*i_next; struct timeb now; int64_t gone; int32_t timeout = (cfg.max_hitcache_time + (cfg.max_hitcache_time / 2))*1000; //1,5 SAFE_RWLOCK_WRLOCK(&hitcache_lock); i = get_first_node_list(&ll_hitcache); while (i) { i_next = i->next; cachehit = get_data_from_node(i); if(!cachehit) { i = i_next; continue; } cs_ftime(&now); gone = comp_timeb(&now, &cachehit->time); if(force || gone>timeout) { remove_elem_list(&ll_hitcache, &cachehit->ll_node); remove_elem_hash_table(&ht_hitcache, &cachehit->ht_node); NULLFREE(cachehit); } i = i_next; } SAFE_RWLOCK_UNLOCK(&hitcache_lock); }
void cleanup_cache(void){ ECMHASH *ecmhash; CW *cw; struct s_pushclient *pc, *nxt; node *i,*i_next,*j,*j_next; struct timeb now; int32_t gone_first, gone_upd; pthread_rwlock_wrlock(&cache_lock); i = get_first_node_list(&ll_cache); while (i) { i_next = i->next; ecmhash = get_data_from_node(i); cs_ftime(&now); gone_first = comp_timeb(&now, &ecmhash->first_recv_time); gone_upd = comp_timeb(&now, &ecmhash->upd_time); if(ecmhash && gone_first<=(cfg.max_cache_time*1000)){ //not continue, useless check for nexts one! break; } if(ecmhash && gone_upd>(cfg.max_cache_time*1000)){ j = get_first_node_list(&ecmhash->ll_cw); while (j) { j_next = j->next; cw = get_data_from_node(j); if(cw){ pthread_rwlock_destroy(&cw->pushout_client_lock); pc = cw->pushout_client; cw->pushout_client=NULL; while (pc) { nxt = pc->next_push; NULLFREE(pc); pc = nxt; } remove_elem_list(&ecmhash->ll_cw, &cw->ll_node); remove_elem_hash_table(&ecmhash->ht_cw, &cw->ht_node); NULLFREE(cw); } j = j_next; } deinitialize_hash_table(&ecmhash->ht_cw); remove_elem_list(&ll_cache, &ecmhash->ll_node); remove_elem_hash_table(&ht_cache, &ecmhash->ht_node); NULLFREE(ecmhash); } i = i_next; } pthread_rwlock_unlock(&cache_lock); }