* @brief this function is called by all eviction algorithms to initialize the * cache * * @param ccache_params common cache parameters * @param init_params eviction algorithm specific parameters * @return cache_t* pointer to the cache */
| 26 | * @return cache_t* pointer to the cache |
| 27 | */ |
| 28 | cache_t *cache_struct_init(const char *const cache_name, const common_cache_params_t params, |
| 29 | const void *const init_params) { |
| 30 | cache_t *cache = my_malloc(cache_t); |
| 31 | memset(cache, 0, sizeof(cache_t)); |
| 32 | strncpy(cache->cache_name, cache_name, CACHE_NAME_ARRAY_LEN-1); |
| 33 | cache->cache_name[CACHE_NAME_ARRAY_LEN-1] = '\0'; |
| 34 | if (init_params != NULL) { |
| 35 | strncpy(cache->init_params, init_params, CACHE_INIT_PARAMS_LEN-1); |
| 36 | cache->init_params[CACHE_INIT_PARAMS_LEN-1] = '\0'; |
| 37 | } |
| 38 | cache->cache_size = params.cache_size; |
| 39 | cache->eviction_params = NULL; |
| 40 | cache->admissioner = NULL; |
| 41 | cache->prefetcher = NULL; |
| 42 | cache->future_stack_dist = NULL; |
| 43 | cache->future_stack_dist_array_size = 0; |
| 44 | cache->default_ttl = params.default_ttl; |
| 45 | cache->n_req = 0; |
| 46 | cache->to_evict_candidate = NULL; |
| 47 | cache->to_evict_candidate_gen_vtime = -1; |
| 48 | |
| 49 | cache->can_insert = cache_can_insert_default; |
| 50 | cache->get_occupied_byte = cache_get_occupied_byte_default; |
| 51 | cache->get_n_obj = cache_get_n_obj_default; |
| 52 | |
| 53 | /* this option works only when eviction age tracking |
| 54 | * is on in config.h */ |
| 55 | #if defined(TRACK_EVICTION_V_AGE) |
| 56 | cache->track_eviction_age = true; |
| 57 | #endif |
| 58 | #if defined(TRACK_DEMOTION) |
| 59 | cache->track_demotion = true; |
| 60 | #endif |
| 61 | |
| 62 | int hash_power = HASH_POWER_DEFAULT; |
| 63 | if (params.hashpower > 0 && params.hashpower < 40) hash_power = params.hashpower; |
| 64 | cache->hashtable = create_hashtable(hash_power); |
| 65 | hashtable_add_ptr_to_monitoring(cache->hashtable, &cache->q_head); |
| 66 | hashtable_add_ptr_to_monitoring(cache->hashtable, &cache->q_tail); |
| 67 | |
| 68 | return cache; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @brief this function is called by all eviction algorithms to free the cache |
no outgoing calls
no test coverage detected