From: Sebastian Harl Date: Wed, 9 Jul 2014 07:55:23 +0000 (+0200) Subject: avltree: Lock the tree during insertion. X-Git-Tag: sysdb-0.3.0~69 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;ds=sidebyside;h=52c636cb7309660115f4024821588a173a7ff69a;hp=9c2c414cffe741f3c0737d6af02a059766ce52fd;p=sysdb.git avltree: Lock the tree during insertion. --- diff --git a/src/utils/avltree.c b/src/utils/avltree.c index ce87c52..8c13233 100644 --- a/src/utils/avltree.c +++ b/src/utils/avltree.c @@ -302,9 +302,12 @@ sdb_avltree_insert(sdb_avltree_t *tree, sdb_object_t *obj) if (! n) return -1; + pthread_rwlock_wrlock(&tree->lock); + if (! tree->root) { tree->root = n; tree->size = 1; + pthread_rwlock_unlock(&tree->lock); return 0; } @@ -315,6 +318,7 @@ sdb_avltree_insert(sdb_avltree_t *tree, sdb_object_t *obj) diff = tree->cmp(obj, parent->obj); if (! diff) { node_destroy(n); + pthread_rwlock_unlock(&tree->lock); return -1; } @@ -338,6 +342,7 @@ sdb_avltree_insert(sdb_avltree_t *tree, sdb_object_t *obj) ++tree->size; rebalance(tree, parent); + pthread_rwlock_unlock(&tree->lock); return 0; } /* sdb_avltree_insert */