Module: xenomai-gch
Branch: for-forge
Commit: 1b54efd6dda982f4a262a543b62caa61f4fecf94
URL:    
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=1b54efd6dda982f4a262a543b62caa61f4fecf94

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sun Jan 26 21:37:56 2014 +0100

cobalt/xnid: allow iteration

and return -EEXIST instead of -EBUSY when trying to insert an already
existing index.

---

 include/cobalt/kernel/tree.h |   13 +++++++++++++
 kernel/cobalt/tree.c         |    2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/include/cobalt/kernel/tree.h b/include/cobalt/kernel/tree.h
index 12df1c0..17ae189 100644
--- a/include/cobalt/kernel/tree.h
+++ b/include/cobalt/kernel/tree.h
@@ -28,11 +28,24 @@ struct xnid {
        struct rb_node link;
 };
 
+#define xnid_entry(ptr, type, member)                                  \
+       ({                                                              \
+               typeof(ptr) _ptr = (ptr);                               \
+               (_ptr ? container_of(_ptr, type, member.link) : NULL);  \
+       })
+
+#define xnid_next_entry(ptr, member)                           \
+       xnid_entry(rb_next(&ptr->member.link), typeof(*ptr), member)
+
 static inline void xntree_init(struct rb_root *t)
 {
        *t = RB_ROOT;
 }
 
+#define xntree_for_each_entry(pos, root, member)                       \
+       for (pos = xnid_entry(rb_first(root), typeof(*pos), member);    \
+            pos; pos = xnid_next_entry(pos, member))
+
 void xntree_cleanup(struct rb_root *t, void *cookie,
                void (*destroy)(void *cookie, struct xnid *id));
 
diff --git a/kernel/cobalt/tree.c b/kernel/cobalt/tree.c
index a84179b..7ba953e 100644
--- a/kernel/cobalt/tree.c
+++ b/kernel/cobalt/tree.c
@@ -47,7 +47,7 @@ int xnid_enter(struct rb_root *t, struct xnid *xnid, unsigned 
long long id)
                else if (id > i->id)
                        new = &((*new)->rb_right);
                else
-                       return -EBUSY;
+                       return -EEXIST;
        }
 
        xnid->id = id;


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

Reply via email to