Module: xenomai-forge
Branch: next
Commit: 51e1e3d0e7d223a8d6c92cef830f9b0b091b3973
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=51e1e3d0e7d223a8d6c92cef830f9b0b091b3973

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Apr 16 17:11:59 2013 +0200

copperplate/hash: introduce table scanning function hash_walk()

---

 include/copperplate/hash.h |    8 ++++++
 lib/copperplate/hash.c     |   54 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/include/copperplate/hash.h b/include/copperplate/hash.h
index 40f5c82..1ad712f 100644
--- a/include/copperplate/hash.h
+++ b/include/copperplate/hash.h
@@ -95,6 +95,9 @@ int hash_remove(struct hash_table *t, struct hashobj *delobj);
 
 struct hashobj *hash_search(struct hash_table *t, const char *key);
 
+int hash_walk(struct hash_table *t,
+               int (*walk)(struct hash_table *t, struct hashobj *obj));
+
 #ifdef CONFIG_XENO_PSHARED
 
 int __hash_enter_probe(struct hash_table *t,
@@ -144,12 +147,17 @@ int pvhash_enter_dup(struct pvhash_table *t,
 int pvhash_remove(struct pvhash_table *t, struct pvhashobj *delobj);
 
 struct pvhashobj *pvhash_search(struct pvhash_table *t, const char *key);
+
+int pvhash_walk(struct pvhash_table *t,
+               int (*walk)(struct pvhash_table *t, struct pvhashobj *obj));
+
 #else /* !CONFIG_XENO_PSHARED */
 #define pvhash_init            hash_init
 #define pvhash_enter           hash_enter
 #define pvhash_enter_dup       hash_enter_dup
 #define pvhash_remove          hash_remove
 #define pvhash_search          hash_search
+#define pvhash_walk            hash_walk
 #endif /* !CONFIG_XENO_PSHARED */
 
 #ifdef __cplusplus
diff --git a/lib/copperplate/hash.c b/lib/copperplate/hash.c
index 40104ab..ba0d51a 100644
--- a/lib/copperplate/hash.c
+++ b/lib/copperplate/hash.c
@@ -192,6 +192,33 @@ out:
        return obj;
 }
 
+int hash_walk(struct hash_table *t,
+             int (*walk)(struct hash_table *t, struct hashobj *obj))
+{
+       struct hash_bucket *bucket;
+       struct hashobj *obj, *tmp;
+       int ret, n;
+
+       read_lock_nocancel(&t->lock);
+
+       for (n = 0; n < HASHSLOTS; n++) {
+               bucket = &t->table[n];
+               if (list_empty(&bucket->obj_list))
+                       continue;
+               list_for_each_entry_safe(obj, tmp, &bucket->obj_list, link) {
+                       read_unlock(&t->lock);
+                       ret = walk(t, obj);
+                       if (ret)
+                               return __bt(ret);
+                       read_lock_nocancel(&t->lock);
+               }
+       }
+
+       read_unlock(&t->lock);
+
+       return 0;
+}
+
 #ifdef CONFIG_XENO_PSHARED
 
 int __hash_enter_probe(struct hash_table *t,
@@ -361,4 +388,31 @@ out:
        return obj;
 }
 
+int pvhash_walk(struct pvhash_table *t,
+               int (*walk)(struct pvhash_table *t, struct pvhashobj *obj))
+{
+       struct pvhash_bucket *bucket;
+       struct pvhashobj *obj, *tmp;
+       int ret, n;
+
+       read_lock_nocancel(&t->lock);
+
+       for (n = 0; n < HASHSLOTS; n++) {
+               bucket = &t->table[n];
+               if (pvlist_empty(&bucket->obj_list))
+                       continue;
+               pvlist_for_each_entry_safe(obj, tmp, &bucket->obj_list, link) {
+                       read_unlock(&t->lock);
+                       ret = walk(t, obj);
+                       if (ret)
+                               return __bt(ret);
+                       read_lock_nocancel(&t->lock);
+               }
+       }
+
+       read_unlock(&t->lock);
+
+       return 0;
+}
+
 #endif /* CONFIG_XENO_PSHARED */


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to