void clear_tls() { if(is_init) { if(COMPARE_AND_SWAP(&is_init,1,0) == 1) { pthread_key_delete(thread_key); mutex_lock(tls_mtx); list_iter it = list_begin(tls_list); list_iter end = list_end(tls_list); for( ; !IT_EQ(it,end); IT_NEXT(it)) { hash_map_t h = IT_GET_VAL(hash_map_t,it); hash_map_destroy(&h); } mutex_unlock(tls_mtx); mutex_destroy(&tls_mtx); list_destroy(&tls_list); } } }
int main() { hash_map_t h = hash_map_create(4096,sizeof(int32_t),sizeof(int32_t),_hash_func_,_hash_key_eq_); int32_t i = 1; for( ; i < 10; ++i) { hash_map_iter it = HASH_MAP_INSERT(int32_t,int32_t,h,i,i); printf("%d\n",IT_GET_VAL(int32_t,it)); } printf("----------------------\n"); { hash_map_iter it = HASH_MAP_FIND(int32_t,h,5); hash_map_iter end = hash_map_end(h); if(!IT_EQ(it,end)) printf("%d\n",IT_GET_VAL(int32_t,it)); } printf("----------------------\n"); { hash_map_iter it = HASH_MAP_FIND(int32_t,h,100); hash_map_iter end = hash_map_end(h); if(!IT_EQ(it,end)) printf("%d\n",IT_GET_VAL(int32_t,it)); else printf("can't find 100\n"); } printf("----------------------\n"); HASH_MAP_REMOVE(int32_t,h,5); { hash_map_iter it = hash_map_begin(h); hash_map_iter end = hash_map_end(h); for( ; !IT_EQ(it,end); IT_NEXT(it)) printf("%d\n",IT_GET_VAL(int32_t,it)); } return 0; };