summaryrefslogtreecommitdiffstats
path: root/libnetdata/avl/avl.c
diff options
context:
space:
mode:
Diffstat (limited to 'libnetdata/avl/avl.c')
-rw-r--r--libnetdata/avl/avl.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/libnetdata/avl/avl.c b/libnetdata/avl/avl.c
index c44bef307..521985189 100644
--- a/libnetdata/avl/avl.c
+++ b/libnetdata/avl/avl.c
@@ -17,7 +17,7 @@
/* Search |tree| for an item matching |item|, and return it if found.
Otherwise return |NULL|. */
-avl *avl_search(avl_tree *tree, avl *item) {
+avl *avl_search(avl_tree_type *tree, avl *item) {
avl *p;
// assert (tree != NULL && item != NULL);
@@ -40,7 +40,7 @@ avl *avl_search(avl_tree *tree, avl *item) {
If a duplicate item is found in the tree,
returns a pointer to the duplicate without inserting |item|.
*/
-avl *avl_insert(avl_tree *tree, avl *item) {
+avl *avl_insert(avl_tree_type *tree, avl *item) {
avl *y, *z; /* Top node to update balance factor, and parent. */
avl *p, *q; /* Iterator, and parent. */
avl *n; /* Newly inserted node. */
@@ -136,7 +136,7 @@ avl *avl_insert(avl_tree *tree, avl *item) {
/* Deletes from |tree| and returns an item matching |item|.
Returns a null pointer if no matching item found. */
-avl *avl_remove(avl_tree *tree, avl *item) {
+avl *avl_remove(avl_tree_type *tree, avl *item) {
/* Stack of nodes. */
avl *pa[AVL_MAX_HEIGHT]; /* Nodes. */
unsigned char da[AVL_MAX_HEIGHT]; /* |avl_link[]| indexes. */
@@ -306,7 +306,7 @@ int avl_walker(avl *node, int (*callback)(void * /*entry*/, void * /*data*/), vo
return total;
}
-int avl_traverse(avl_tree *tree, int (*callback)(void * /*entry*/, void * /*data*/), void *data) {
+int avl_traverse(avl_tree_type *tree, int (*callback)(void * /*entry*/, void * /*data*/), void *data) {
if(tree->root)
return avl_walker(tree->root, callback, data);
else
@@ -367,6 +367,22 @@ void avl_init_lock(avl_tree_lock *tree, int (*compar)(void * /*a*/, void * /*b*/
#endif /* AVL_WITHOUT_PTHREADS */
}
+void avl_destroy_lock(avl_tree_lock *tree) {
+#ifndef AVL_WITHOUT_PTHREADS
+ int lock;
+
+#ifdef AVL_LOCK_WITH_MUTEX
+ lock = pthread_mutex_destroy(&tree->mutex);
+#else
+ lock = pthread_rwlock_destroy(&tree->rwlock);
+#endif
+
+ if(lock != 0)
+ fatal("Failed to destroy AVL mutex/rwlock, error: %d", lock);
+
+#endif /* AVL_WITHOUT_PTHREADS */
+}
+
avl *avl_search_lock(avl_tree_lock *tree, avl *item) {
avl_read_lock(tree);
avl *ret = avl_search(&tree->avl_tree, item);
@@ -396,7 +412,7 @@ int avl_traverse_lock(avl_tree_lock *tree, int (*callback)(void * /*entry*/, voi
return ret;
}
-void avl_init(avl_tree *tree, int (*compar)(void * /*a*/, void * /*b*/)) {
+void avl_init(avl_tree_type *tree, int (*compar)(void * /*a*/, void * /*b*/)) {
tree->root = NULL;
tree->compar = compar;
}