summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/rbthash.c
diff options
context:
space:
mode:
authorRaghavendra G <raghavendra@gluster.com>2011-06-14 01:41:24 +0000
committerAnand Avati <avati@gluster.com>2011-06-14 22:37:35 -0700
commite8f67179ca60eb81a4b1fa92e37bd0eb6213d659 (patch)
tree8bc2cdba11d8a566671eee4334d9969bced2e573 /libglusterfs/src/rbthash.c
parent72d56ff2a8bd0eacfa8036f7583fc0dd4de460d0 (diff)
rbthashtable: implement traverser procedure.
Signed-off-by: Raghavendra G <raghavendra@gluster.com> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 1059 (enhancements for getting statistics from performance translators) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1059
Diffstat (limited to 'libglusterfs/src/rbthash.c')
-rw-r--r--libglusterfs/src/rbthash.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/libglusterfs/src/rbthash.c b/libglusterfs/src/rbthash.c
index 2f41d9825b4..64fe70a8edd 100644
--- a/libglusterfs/src/rbthash.c
+++ b/libglusterfs/src/rbthash.c
@@ -141,6 +141,7 @@ rbthash_table_init (int buckets, rbt_hasher_t hfunc,
}
LOCK_INIT (&newtab->tablelock);
+ INIT_LIST_HEAD (&newtab->list);
newtab->numbuckets = buckets;
ret = __rbthash_init_buckets (newtab, buckets);
@@ -191,6 +192,7 @@ rbthash_init_entry (rbthash_table_t *tbl, void *data, void *key, int keylen)
goto free_entry;
}
+ INIT_LIST_HEAD (&entry->list);
memcpy (entry->key, key, keylen);
entry->keylen = keylen;
entry->keyhash = tbl->hashfunc (entry->key, entry->keylen);
@@ -221,6 +223,13 @@ rbthash_deinit_entry (rbthash_table_t *tbl, rbthash_entry_t *entry)
if (tbl) {
if ((entry->data) && (tbl->dfunc))
tbl->dfunc (entry->data);
+
+ LOCK (&tbl->tablelock);
+ {
+ list_del_init (&entry->list);
+ }
+ UNLOCK (&tbl->tablelock);
+
mem_put (tbl->entrypool, entry);
}
@@ -292,6 +301,12 @@ rbthash_insert (rbthash_table_t *tbl, void *data, void *key, int keylen)
rbthash_deinit_entry (tbl, entry);
}
+ LOCK (&tbl->tablelock);
+ {
+ list_add_tail (&entry->list, &tbl->list);
+ }
+ UNLOCK (&tbl->tablelock);
+
err:
return ret;
}
@@ -376,6 +391,13 @@ rbthash_remove (rbthash_table_t *tbl, void *key, int keylen)
GF_FREE (entry->key);
dataref = entry->data;
+
+ LOCK (&tbl->tablelock);
+ {
+ list_del_init (&entry->list);
+ }
+ UNLOCK (&tbl->tablelock);
+
mem_put (tbl->entrypool, entry);
return dataref;
@@ -421,3 +443,26 @@ rbthash_table_destroy (rbthash_table_t *tbl)
GF_FREE (tbl->buckets);
GF_FREE (tbl);
}
+
+
+void
+rbthash_table_traverse (rbthash_table_t *tbl, rbt_traverse_t traverse,
+ void *mydata)
+{
+ rbthash_entry_t *entry = NULL;
+
+ if ((tbl == NULL) || (traverse == NULL)) {
+ goto out;
+ }
+
+ LOCK (&tbl->tablelock);
+ {
+ list_for_each_entry (entry, &tbl->list, list) {
+ traverse (entry->data, mydata);
+ }
+ }
+ UNLOCK (&tbl->tablelock);
+
+out:
+ return;
+}