Commit 385d65b8 authored by Karl Heyes's avatar Karl Heyes
Browse files

Don't include a per node lock unless it is really wanted. I don't think anyone

is using them currently, so lets reduce the structure size.  On win32, this
extra lock increases the handles usage considerably.

svn path=/icecast/trunk/avl/; revision=15120
parent d3f01371
...@@ -54,7 +54,9 @@ avl_node_new (void * key, ...@@ -54,7 +54,9 @@ avl_node_new (void * key,
node->rank_and_balance = 0; node->rank_and_balance = 0;
AVL_SET_BALANCE (node, 0); AVL_SET_BALANCE (node, 0);
AVL_SET_RANK (node, 1); AVL_SET_RANK (node, 1);
#ifdef HAVE_AVL_NODE_LOCK
thread_rwlock_create(&node->rwlock); thread_rwlock_create(&node->rwlock);
#endif
return node; return node;
} }
} }
...@@ -95,7 +97,9 @@ avl_tree_free_helper (avl_node * node, avl_free_key_fun_type free_key_fun) ...@@ -95,7 +97,9 @@ avl_tree_free_helper (avl_node * node, avl_free_key_fun_type free_key_fun)
if (node->right) { if (node->right) {
avl_tree_free_helper (node->right, free_key_fun); avl_tree_free_helper (node->right, free_key_fun);
} }
#ifdef HAVE_AVL_NODE_LOCK
thread_rwlock_destroy (&node->rwlock); thread_rwlock_destroy (&node->rwlock);
#endif
free (node); free (node);
} }
...@@ -106,7 +110,9 @@ avl_tree_free (avl_tree * tree, avl_free_key_fun_type free_key_fun) ...@@ -106,7 +110,9 @@ avl_tree_free (avl_tree * tree, avl_free_key_fun_type free_key_fun)
avl_tree_free_helper (tree->root->right, free_key_fun); avl_tree_free_helper (tree->root->right, free_key_fun);
} }
if (tree->root) { if (tree->root) {
#ifdef HAVE_AVL_NODE_LOCK
thread_rwlock_destroy(&tree->root->rwlock); thread_rwlock_destroy(&tree->root->rwlock);
#endif
free (tree->root); free (tree->root);
} }
thread_rwlock_destroy(&tree->rwlock); thread_rwlock_destroy(&tree->rwlock);
...@@ -450,7 +456,9 @@ int avl_delete(avl_tree *tree, void *key, avl_free_key_fun_type free_key_fun) ...@@ -450,7 +456,9 @@ int avl_delete(avl_tree *tree, void *key, avl_free_key_fun_type free_key_fun)
/* return the key and node to storage */ /* return the key and node to storage */
if (free_key_fun) if (free_key_fun)
free_key_fun (x->key); free_key_fun (x->key);
#ifdef HAVE_AVL_NODE_LOCK
thread_rwlock_destroy (&x->rwlock); thread_rwlock_destroy (&x->rwlock);
#endif
free (x); free (x);
while (shorter && p->parent) { while (shorter && p->parent) {
...@@ -1168,6 +1176,7 @@ void avl_tree_unlock(avl_tree *tree) ...@@ -1168,6 +1176,7 @@ void avl_tree_unlock(avl_tree *tree)
thread_rwlock_unlock(&tree->rwlock); thread_rwlock_unlock(&tree->rwlock);
} }
#ifdef HAVE_AVL_NODE_LOCK
void avl_node_rlock(avl_node *node) void avl_node_rlock(avl_node *node)
{ {
thread_rwlock_rlock(&node->rwlock); thread_rwlock_rlock(&node->rwlock);
...@@ -1182,3 +1191,4 @@ void avl_node_unlock(avl_node *node) ...@@ -1182,3 +1191,4 @@ void avl_node_unlock(avl_node *node)
{ {
thread_rwlock_unlock(&node->rwlock); thread_rwlock_unlock(&node->rwlock);
} }
#endif
...@@ -32,7 +32,7 @@ typedef struct avl_node_tag { ...@@ -32,7 +32,7 @@ typedef struct avl_node_tag {
* The rest of the bits are used for <rank> * The rest of the bits are used for <rank>
*/ */
unsigned int rank_and_balance; unsigned int rank_and_balance;
#ifndef NO_THREAD #if !defined(NO_THREAD) && defined(HAVE_AVL_NODE_LOCK)
rwlock_t rwlock; rwlock_t rwlock;
#endif #endif
} avl_node; } avl_node;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment