void lru_cache_insert(lru_cache_t* lru, DIR_handle_t handle, struct giga_directory* entry) { ACQUIRE_MUTEX(&(lru->mutex_), "lru_cache_insert(%d)", handle); // printf("INSERT %d %d, length: %ld, cap: %ld\n", handle, entry->split_flag, lru->length_+1, lru->capacity_); struct giga_directory* old; HASH_FIND_INT(lru->table, &handle, old); if (old != NULL) { HASH_DEL(lru->table, old); double_list_remove(old); lru_cache_unref(old); } else { ++lru->length_; } HASH_ADD_INT(lru->table, handle, entry); double_list_append(&(lru->dummy), entry); entry->refcount = 2; while (lru->length_ > lru->capacity_ && lru->dummy.next != &(lru->dummy)) { struct giga_directory* old = lru->dummy.next; // printf("EVICT ENTRY %d\n", old->handle); HASH_DEL(lru->table, old); double_list_remove(old); lru_cache_unref(old); --lru->length_; } RELEASE_MUTEX(&(lru->mutex_), "lru_cache_insert(%d)", handle); }
struct giga_directory* lru_cache_lookup(lru_cache_t* lru, DIR_handle_t handle) { ACQUIRE_MUTEX(&(lru->mutex_), "lru_cache_lookup(%d)", handle); struct giga_directory* entry; HASH_FIND_INT(lru->table, &handle, entry); /* if (entry != NULL) { printf("LOOKUP: %d %d\n", handle, entry->split_flag); } else { printf("LOOKUP: %d NULL\n", handle); } */ if (entry != NULL) { entry->refcount ++; double_list_remove(entry); double_list_append(&(lru->dummy), entry); } RELEASE_MUTEX(&(lru->mutex_), "lru_cache_lookup(%d)", handle); return entry; }
void _my_free(void* p) { struct alloc_debug_node* m = (struct alloc_debug_node*)p; --m; WRITELOCK(_g_alloc_debug_list._locker); double_list_remove(&_g_alloc_debug_list._link,&m->_link_node); _g_alloc_debug_list._count --; WRITEUNLOCK(_g_alloc_debug_list._locker); free(m); }
void lru_cache_erase(lru_cache_t* lru, DIR_handle_t handle) { ACQUIRE_MUTEX(&(lru->mutex_), "lru_cache_erase(%d)", handle); struct giga_directory* old; HASH_FIND_INT(lru->table, &handle, old); if (old != NULL) { // printf("DEL %d %d %d\n", old->handle, old->split_flag, old->refcount); double_list_remove(old); HASH_DEL(lru->table, old); lru_cache_unref(old); --lru->length_; } RELEASE_MUTEX(&(lru->mutex_), "lru_cache_erase(%d)", handle); }