void name_tree_destroy(name_tree_t *tree) { mem_pool_delete(tree->node_pool); mem_pool_delete(tree->name_pool); heap_destory(tree->heap); lru_list_destroy(tree->lru); free(tree->_tree); free(tree); }
static void force_stop_thread(thread_t *t) { pthread_cancel(t->tid); pthread_cond_destroy(&t->task_list_aval_cond); pthread_mutex_destroy(&t->task_list_lock); mem_pool_delete(t->mem_pool); }
name_tree_t * name_tree_create() { name_tree_t *tree = calloc(1, sizeof(name_tree_t)); if (!tree) return NULL; tree->_tree = rbtree_create(name_compare); if (!tree->_tree) goto MEM_ALLOC_FAILED; tree->heap = heap_init(1000, elem_compare); if (!tree->heap) goto MEM_ALLOC_FAILED; tree->node_pool = mem_pool_create(sizeof(rbnode_t), 1024, true); if (!tree->node_pool) goto MEM_ALLOC_FAILED; tree->name_pool = mem_pool_create(sizeof(node_value_t), 1024, true); if (!tree->name_pool) goto MEM_ALLOC_FAILED; tree->lru = lru_list_create(); if (!tree->lru) goto MEM_ALLOC_FAILED; tree->count = 0; return tree; MEM_ALLOC_FAILED : if (tree->name_pool) mem_pool_delete(tree->name_pool); if (tree->node_pool) mem_pool_delete(tree->node_pool); if (tree->_tree) free(tree->_tree); if (tree->heap) heap_destory(tree->heap); if (tree->lru) lru_list_destroy(tree->lru); free(tree); }
HASH_TABLE * create_hash_table (char *hashname, int buckets, int (*cmp)(char *list, char *key), int (*index_gen)(char *key), int key_len) { HASH_TABLE * htable = NULL; int size = (sizeof (hash_bucket_t *)) * ((!buckets) ? (buckets = DEFAULT_HASH_BUCKETS) : buckets); htable = (HASH_TABLE *) malloc (sizeof (HASH_TABLE)); if (!htable) { return NULL; } strcpy (htable->htname, hashname); htable->nbuckets = buckets; htable->key_len = key_len; htable->cmp_func = cmp; htable->hash_index_gen = index_gen; htable->nentries = 0; htable->hmem_pool_id = mem_pool_create (hashname, size, buckets, 0); if (htable->hmem_pool_id < 0) { free (htable); return NULL; } htable->bucket_array = (hash_bucket_t **) malloc (buckets * sizeof (hash_bucket_t *)); if (!htable->bucket_array) { mem_pool_delete (htable->hmem_pool_id); free (htable); } return htable; }
static void stop_thread(thread_t *t) { ASSERT(t, "stop empty thread"); t->state = DONE; /* * signal the condition, in case the thread is blocked on the * condition wait. using the lock is to make sure the thread can * get the signal if it really blocked on the condition wait * */ pthread_mutex_lock(&t->task_list_lock); pthread_cond_signal(&t->task_list_aval_cond); pthread_mutex_unlock(&t->task_list_lock); //pthread_cancel(t->tid);FIXME by liuxy //pthread_detach(t->tid); //liuxy pthread_join(t->tid, NULL); pthread_cond_destroy(&t->task_list_aval_cond); pthread_mutex_destroy(&t->task_list_lock); mem_pool_delete(t->mem_pool); }
void destroy_hash_table (HASH_TABLE *htbl, void (*free_data) (void *)) { flush_hash_table (htbl, free_data); mem_pool_delete (htbl->hmem_pool_id); }