GAULFUNC void avltree_delete(AVLTree *tree) { if (!tree) return; avltree_node_delete(tree->root); s_free(tree); AVLnum_trees--; THREAD_LOCK(avltree_node_buffer_lock); if (AVLnum_trees == 0) _destroy_buffers(); THREAD_UNLOCK(avltree_node_buffer_lock); return; }
GAULFUNC void avltree_destroy(AVLTree *tree, AVLDestructorFunc free_func) { if (!tree) return; if (free_func!=NULL) avltree_node_destroy(tree->root, free_func); else avltree_node_delete(tree->root); s_free(tree); AVLnum_trees--; THREAD_LOCK(avltree_node_buffer_lock); if (AVLnum_trees == 0) _destroy_buffers(); THREAD_UNLOCK(avltree_node_buffer_lock); return; }
int knet_handle_free(knet_handle_t knet_h) { int savederrno = 0; savederrno = pthread_mutex_lock(&handle_config_mutex); if (savederrno) { log_err(knet_h, KNET_SUB_HANDLE, "Unable to get handle mutex lock: %s", strerror(savederrno)); errno = savederrno; return -1; } if (!knet_h) { pthread_mutex_unlock(&handle_config_mutex); errno = EINVAL; return -1; } if (knet_h->fini_in_progress) { pthread_mutex_unlock(&handle_config_mutex); errno = EBUSY; return -1; } /* * we take a chance here to read a value that should be 0 * only if we could not init properly. Nothing else * is started if lock_init_done is 0. */ if (!knet_h->lock_init_done) { goto exit_nolock; } savederrno = pthread_rwlock_wrlock(&knet_h->list_rwlock); if (savederrno) { log_err(knet_h, KNET_SUB_HANDLE, "Unable to get write lock: %s", strerror(savederrno)); errno = savederrno; return -1; } if ((knet_h->host_head != NULL) || (knet_h->listener_head != NULL)) { savederrno = EBUSY; log_err(knet_h, KNET_SUB_HANDLE, "Unable to free handle: host(s) or listener(s) are still active: %s", strerror(savederrno)); pthread_rwlock_unlock(&knet_h->list_rwlock); errno = savederrno; return -1; } knet_h->fini_in_progress = 1; pthread_rwlock_unlock(&knet_h->list_rwlock); _stop_threads(knet_h); _close_epolls(knet_h); _destroy_buffers(knet_h); _close_socks(knet_h); crypto_fini(knet_h); _destroy_locks(knet_h); exit_nolock: free(knet_h); knet_h = NULL; pthread_mutex_unlock(&handle_config_mutex); return 0; }