Module: xenomai-3 Branch: master Commit: 771f61ddaf2d02ddd9b8b3f9ff5acb16f9248854 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=771f61ddaf2d02ddd9b8b3f9ff5acb16f9248854
Author: Philippe Gerum <r...@xenomai.org> Date: Wed Mar 11 22:04:51 2015 +0100 copperplate/cluster: add support for walking a cluster --- include/copperplate/cluster.h | 87 +++++++++++++++++++++++++++++++++++++++++ lib/copperplate/cluster.c | 59 +++++++++++++++++++++++++++- 2 files changed, 145 insertions(+), 1 deletion(-) diff --git a/include/copperplate/cluster.h b/include/copperplate/cluster.h index 34da167..0f75690 100644 --- a/include/copperplate/cluster.h +++ b/include/copperplate/cluster.h @@ -57,6 +57,42 @@ struct pvsyncluster { struct syncobj sobj; }; +static inline +const void *clusterobj_key(const struct clusterobj *cobj) +{ + return __memptr(__main_heap, cobj->hobj.key); +} + +static inline +size_t clusterobj_keylen(const struct clusterobj *cobj) +{ + return cobj->hobj.len; +} + +static inline +pid_t clusterobj_cnode(const struct clusterobj *cobj) +{ + return cobj->cnode; +} + +static inline +const void *pvclusterobj_key(const struct pvclusterobj *cobj) +{ + return cobj->hobj.key; +} + +static inline +size_t pvclusterobj_keylen(const struct pvclusterobj *cobj) +{ + return cobj->hobj.len; +} + +static inline +pid_t pvclusterobj_cnode(const struct pvclusterobj *cobj) +{ + return -1; +} + #else /* !CONFIG_XENO_PSHARED */ struct clusterobj { @@ -76,6 +112,42 @@ struct syncluster { #define pvcluster cluster #define pvsyncluster syncluster +static inline +const void *clusterobj_key(const struct pvclusterobj *cobj) +{ + return cobj->hobj.key; +} + +static inline +size_t clusterobj_keylen(const struct pvclusterobj *cobj) +{ + return cobj->hobj.len; +} + +static inline +pid_t clusterobj_cnode(const struct pvclusterobj *cobj) +{ + return -1; +} + +static inline +const void *pvclusterobj_key(const struct pvclusterobj *cobj) +{ + return clusterobj_key(cobj); +} + +static inline +size_t pvclusterobj_keylen(const struct pvclusterobj *cobj) +{ + return clusterobj_keylen(cobj); +} + +static inline +pid_t pvclusterobj_cnode(const struct pvclusterobj *cobj) +{ + return clusterobj_cnode(cobj); +} + #endif /* !CONFIG_XENO_PSHARED */ struct syncluster_wait_struct { @@ -102,6 +174,10 @@ int pvcluster_delobj(struct pvcluster *c, struct pvclusterobj *pvcluster_findobj(struct pvcluster *c, const char *name); +int pvcluster_walk(struct pvcluster *c, + int (*walk)(struct pvcluster *c, + struct pvclusterobj *cobj)); + int pvsyncluster_init(struct pvsyncluster *sc, const char *name); void pvsyncluster_destroy(struct pvsyncluster *sc); @@ -133,6 +209,10 @@ int cluster_delobj(struct cluster *c, struct clusterobj *cluster_findobj(struct cluster *c, const char *name); +int cluster_walk(struct cluster *c, + int (*walk)(struct cluster *c, + struct clusterobj *cobj)); + int syncluster_init(struct syncluster *sc, const char *name); int syncluster_addobj(struct syncluster *sc, const char *name, @@ -177,6 +257,13 @@ static inline struct clusterobj *cluster_findobj(struct cluster *c, return pvcluster_findobj(c, name); } +static inline int cluster_walk(struct cluster *c, + int (*walk)(struct cluster *c, + struct clusterobj *cobj)) +{ + return pvcluster_walk(c, walk); +} + static inline int syncluster_init(struct syncluster *sc, const char *name) { diff --git a/lib/copperplate/cluster.c b/lib/copperplate/cluster.c index 28e24c8..80923bc 100644 --- a/lib/copperplate/cluster.c +++ b/lib/copperplate/cluster.c @@ -100,13 +100,25 @@ const static struct hash_operations hash_operations; +struct cluster_walk_data { + struct cluster *c; + int (*walk)(struct cluster *c, + struct clusterobj *cobj); +}; + +struct pvcluster_walk_data { + struct pvcluster *c; + int (*walk)(struct pvcluster *c, + struct pvclusterobj *cobj); +}; + #ifdef CONFIG_XENO_PSHARED int cluster_init(struct cluster *c, const char *name) { struct dictionary *d; struct hashobj *hobj; - int ret = 0; + int ret; /* * NOTE: it does not make sense to destroy a shared cluster @@ -122,6 +134,7 @@ redo: &hash_operations); if (hobj) { d = container_of(hobj, struct dictionary, hobj); + ret = 0; goto out; } @@ -140,6 +153,7 @@ redo: * cluster right after we failed retrieving it: retry * the whole process. */ + hash_destroy(&d->table); xnfree(d); goto redo; } @@ -212,6 +226,27 @@ struct clusterobj *cluster_findobj(struct cluster *c, const char *name) return container_of(hobj, struct clusterobj, hobj); } +static int __cluster_walk(struct hash_table *t, struct hashobj *hobj, void *arg) +{ + struct cluster_walk_data *wd = arg; + struct clusterobj *cobj; + + cobj = container_of(hobj, struct clusterobj, hobj); + + return wd->walk(wd->c, cobj); +} + +int cluster_walk(struct cluster *c, + int (*walk)(struct cluster *c, + struct clusterobj *cobj)) +{ + struct cluster_walk_data wd = { + .c = c, + .walk = walk, + }; + return hash_walk(&c->d->table, __cluster_walk, &wd); +} + int syncluster_init(struct syncluster *sc, const char *name) { int ret; @@ -385,6 +420,28 @@ struct pvclusterobj *pvcluster_findobj(struct pvcluster *c, const char *name) return container_of(hobj, struct pvclusterobj, hobj); } +static int __pvcluster_walk(struct pvhash_table *t, struct pvhashobj *hobj, + void *arg) +{ + struct pvcluster_walk_data *wd = arg; + struct pvclusterobj *cobj; + + cobj = container_of(hobj, struct pvclusterobj, hobj); + + return wd->walk(wd->c, cobj); +} + +int pvcluster_walk(struct pvcluster *c, + int (*walk)(struct pvcluster *c, + struct pvclusterobj *cobj)) +{ + struct pvcluster_walk_data wd = { + .c = c, + .walk = walk, + }; + return pvhash_walk(&c->table, __pvcluster_walk, &wd); +} + int pvsyncluster_init(struct pvsyncluster *sc, const char *name) { int ret; _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git