/* Destroy Hash Table */ void esif_ht_destroy( struct esif_ht *self, item_destroy_func item_destroy_fptr ) { u32 index = 0; if ((self == NULL) || (self->table == NULL)) { ESIF_TRACE_ERROR("Hash table ptr NULL\n"); goto exit; } ESIF_TRACE_DYN_VERB("Destroying hash table %p\n", self); for (index = 0; index < self->size; ++index) { if (self->table[index] == NULL) continue; ESIF_TRACE_DYN_VERB("Destroy linked list %d\n", index); esif_destroy_ht_nodes(self->table[index], item_destroy_fptr); esif_link_list_destroy(self->table[index]); self->table[index] = NULL; } esif_ccb_free(self->table); esif_ccb_mempool_free(ESIF_MEMPOOL_TYPE_HASH2, self); exit: return; }
/* Destroy Linked List */ void esif_link_list_destroy(struct esif_link_list *list_ptr) { struct esif_link_list_node *curr_ptr = list_ptr->head_ptr; while (curr_ptr) { struct esif_link_list_node *next_node_ptr = curr_ptr->next_ptr; esif_link_list_destroy_node(curr_ptr); curr_ptr = next_node_ptr; } esif_ccb_mempool_free(ESIF_MEMPOOL_TYPE_LIST, list_ptr); }
/* Create Hash Table */ struct esif_ht * esif_ht_create( u32 size ) { u32 index = 0; struct esif_ht *new_ht_ptr = NULL; new_ht_ptr = (struct esif_ht *) esif_ccb_mempool_zalloc(ESIF_MEMPOOL_TYPE_HASH2); if (NULL == new_ht_ptr) { ESIF_TRACE_ERROR("Cannot allocate mem for hash table\n"); ESIF_ASSERT(ESIF_FALSE); goto exit; } new_ht_ptr->size = size; new_ht_ptr->table = (struct esif_link_list **) esif_ccb_malloc(sizeof(*new_ht_ptr->table) * size); if (new_ht_ptr->table == NULL) { esif_ccb_mempool_free(ESIF_MEMPOOL_TYPE_HASH2, new_ht_ptr); new_ht_ptr = NULL; goto exit; } for (index = 0; index < size; ++index) { ESIF_TRACE_DYN_VERB("Create linked list %d\n", index); new_ht_ptr->table[index] = esif_link_list_create(); if (new_ht_ptr->table[index] == NULL) { ESIF_TRACE_DYN_VERB("Creation failed\n"); esif_ht_destroy(new_ht_ptr, NULL); new_ht_ptr = NULL; goto exit; } } ESIF_TRACE_DYN_VERB("Have hash table %p\n", new_ht_ptr); exit: return new_ht_ptr; }
/* Destroy Node */ void esif_link_list_destroy_node(struct esif_link_list_node *node_ptr) { esif_ccb_mempool_free(ESIF_MEMPOOL_TYPE_LIST_NODE, node_ptr); }