[Xenomai-git] Philippe Gerum : boilerplate/hash: pass opaque arg to table walk handler
Module: xenomai-3 Branch: master Commit: 97132d8ad817f374708a980efe11bd83ac8fde2b URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=97132d8ad817f374708a980efe11bd83ac8fde2b Author: Philippe Gerum r...@xenomai.org Date: Wed Mar 11 22:01:35 2015 +0100 boilerplate/hash: pass opaque arg to table walk handler --- include/boilerplate/hash.h | 10 ++ lib/boilerplate/hash.c | 14 -- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/boilerplate/hash.h b/include/boilerplate/hash.h index 081aefe..2d77d2f 100644 --- a/include/boilerplate/hash.h +++ b/include/boilerplate/hash.h @@ -54,7 +54,8 @@ struct hash_operations { }; typedef int (*hash_walk_op)(struct hash_table *t, - struct hashobj *obj); + struct hashobj *obj, + void *arg); #ifdef CONFIG_XENO_PSHARED @@ -82,7 +83,8 @@ struct pvhash_operations { }; typedef int (*pvhash_walk_op)(struct pvhash_table *t, - struct pvhashobj *obj); + struct pvhashobj *obj, + void *arg); #else /* !CONFIG_XENO_PSHARED */ #define pvhashobj hashobj @@ -137,7 +139,7 @@ struct hashobj *hash_search(struct hash_table *t, const struct hash_operations *hops); int hash_walk(struct hash_table *t, - hash_walk_op walk); + hash_walk_op walk, void *arg); #ifdef CONFIG_XENO_PSHARED @@ -203,7 +205,7 @@ struct pvhashobj *pvhash_search(struct pvhash_table *t, const struct pvhash_operations *hops); int pvhash_walk(struct pvhash_table *t, - pvhash_walk_op walk); + pvhash_walk_op walk, void *arg); #else /* !CONFIG_XENO_PSHARED */ #define pvhash_inithash_init diff --git a/lib/boilerplate/hash.c b/lib/boilerplate/hash.c index c7f5a50..35fcf73 100644 --- a/lib/boilerplate/hash.c +++ b/lib/boilerplate/hash.c @@ -212,7 +212,7 @@ out: return obj; } -int hash_walk(struct hash_table *t, hash_walk_op walk) +int hash_walk(struct hash_table *t, hash_walk_op walk, void *arg) { struct hash_bucket *bucket; struct hashobj *obj, *tmp; @@ -226,7 +226,7 @@ int hash_walk(struct hash_table *t, hash_walk_op walk) continue; list_for_each_entry_safe(obj, tmp, bucket-obj_list, link) { read_unlock(t-lock); - ret = walk(t, obj); + ret = walk(t, obj, arg); if (ret) return __bt(ret); read_lock_nocancel(t-lock); @@ -266,8 +266,10 @@ static inline int store_key(struct hashobj *obj, static inline void drop_key(struct hashobj *obj, const struct hash_operations *hops) { - if (obj-key != __moff(obj-static_key)) - hops-free((void *)__mptr(obj-key)); + const void *key = __mptr(obj-key); + + if (key != obj-static_key) + hops-free((void *)key); } int __hash_enter_probe(struct hash_table *t, @@ -461,7 +463,7 @@ out: return obj; } -int pvhash_walk(struct pvhash_table *t,pvhash_walk_op walk) +int pvhash_walk(struct pvhash_table *t,pvhash_walk_op walk, void *arg) { struct pvhash_bucket *bucket; struct pvhashobj *obj, *tmp; @@ -475,7 +477,7 @@ int pvhash_walk(struct pvhash_table *t, pvhash_walk_op walk) continue; pvlist_for_each_entry_safe(obj, tmp, bucket-obj_list, link) { read_unlock(t-lock); - ret = walk(t, obj); + ret = walk(t, obj, arg); if (ret) return __bt(ret); read_lock_nocancel(t-lock); ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Philippe Gerum : boilerplate/hash: pass opaque arg to table walk handler
Module: xenomai-3 Branch: next Commit: 97132d8ad817f374708a980efe11bd83ac8fde2b URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=97132d8ad817f374708a980efe11bd83ac8fde2b Author: Philippe Gerum r...@xenomai.org Date: Wed Mar 11 22:01:35 2015 +0100 boilerplate/hash: pass opaque arg to table walk handler --- include/boilerplate/hash.h | 10 ++ lib/boilerplate/hash.c | 14 -- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/boilerplate/hash.h b/include/boilerplate/hash.h index 081aefe..2d77d2f 100644 --- a/include/boilerplate/hash.h +++ b/include/boilerplate/hash.h @@ -54,7 +54,8 @@ struct hash_operations { }; typedef int (*hash_walk_op)(struct hash_table *t, - struct hashobj *obj); + struct hashobj *obj, + void *arg); #ifdef CONFIG_XENO_PSHARED @@ -82,7 +83,8 @@ struct pvhash_operations { }; typedef int (*pvhash_walk_op)(struct pvhash_table *t, - struct pvhashobj *obj); + struct pvhashobj *obj, + void *arg); #else /* !CONFIG_XENO_PSHARED */ #define pvhashobj hashobj @@ -137,7 +139,7 @@ struct hashobj *hash_search(struct hash_table *t, const struct hash_operations *hops); int hash_walk(struct hash_table *t, - hash_walk_op walk); + hash_walk_op walk, void *arg); #ifdef CONFIG_XENO_PSHARED @@ -203,7 +205,7 @@ struct pvhashobj *pvhash_search(struct pvhash_table *t, const struct pvhash_operations *hops); int pvhash_walk(struct pvhash_table *t, - pvhash_walk_op walk); + pvhash_walk_op walk, void *arg); #else /* !CONFIG_XENO_PSHARED */ #define pvhash_inithash_init diff --git a/lib/boilerplate/hash.c b/lib/boilerplate/hash.c index c7f5a50..35fcf73 100644 --- a/lib/boilerplate/hash.c +++ b/lib/boilerplate/hash.c @@ -212,7 +212,7 @@ out: return obj; } -int hash_walk(struct hash_table *t, hash_walk_op walk) +int hash_walk(struct hash_table *t, hash_walk_op walk, void *arg) { struct hash_bucket *bucket; struct hashobj *obj, *tmp; @@ -226,7 +226,7 @@ int hash_walk(struct hash_table *t, hash_walk_op walk) continue; list_for_each_entry_safe(obj, tmp, bucket-obj_list, link) { read_unlock(t-lock); - ret = walk(t, obj); + ret = walk(t, obj, arg); if (ret) return __bt(ret); read_lock_nocancel(t-lock); @@ -266,8 +266,10 @@ static inline int store_key(struct hashobj *obj, static inline void drop_key(struct hashobj *obj, const struct hash_operations *hops) { - if (obj-key != __moff(obj-static_key)) - hops-free((void *)__mptr(obj-key)); + const void *key = __mptr(obj-key); + + if (key != obj-static_key) + hops-free((void *)key); } int __hash_enter_probe(struct hash_table *t, @@ -461,7 +463,7 @@ out: return obj; } -int pvhash_walk(struct pvhash_table *t,pvhash_walk_op walk) +int pvhash_walk(struct pvhash_table *t,pvhash_walk_op walk, void *arg) { struct pvhash_bucket *bucket; struct pvhashobj *obj, *tmp; @@ -475,7 +477,7 @@ int pvhash_walk(struct pvhash_table *t, pvhash_walk_op walk) continue; pvlist_for_each_entry_safe(obj, tmp, bucket-obj_list, link) { read_unlock(t-lock); - ret = walk(t, obj); + ret = walk(t, obj, arg); if (ret) return __bt(ret); read_lock_nocancel(t-lock); ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git