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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Sep  9 12:19:25 2014 +0200

cobalt/registry, cobalt/thread: use wait context in binding operation

---

 include/cobalt/kernel/thread.h |    2 --
 kernel/cobalt/registry.c       |   19 +++++++++++++------
 kernel/cobalt/thread.c         |    1 -
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index 0801cbc..03faf8f 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -169,8 +169,6 @@ struct xnthread {
 
        xnhandle_t handle;      /* Handle in registry */
 
-       const char *waitkey;    /* Pended key */
-
        char name[XNOBJECT_NAME_LEN]; /* Symbolic name of thread */
 
        void (*entry)(void *cookie); /* Thread entry routine */
diff --git a/kernel/cobalt/registry.c b/kernel/cobalt/registry.c
index 561c8d9..6643865 100644
--- a/kernel/cobalt/registry.c
+++ b/kernel/cobalt/registry.c
@@ -559,15 +559,22 @@ static struct xnobject *registry_hash_find(const char 
*key)
        return NULL;
 }
 
+struct registry_wait_context {
+       struct xnthread_wait_context wc;
+       const char *key;
+};
+
 static inline int registry_wakeup_sleepers(const char *key)
 {
+       struct registry_wait_context *rwc;
+       struct xnthread_wait_context *wc;
        struct xnthread *sleeper, *tmp;
        int cnt = 0;
 
        xnsynch_for_each_sleeper_safe(sleeper, tmp, &register_synch) {
-               if (*key == *sleeper->waitkey &&
-                   strcmp(key, sleeper->waitkey) == 0) {
-                       sleeper->waitkey = NULL;
+               wc = xnthread_get_wait_context(sleeper);
+               rwc = container_of(wc, struct registry_wait_context, wc);
+               if (*key == *rwc->key && strcmp(key, rwc->key) == 0) {
                        xnsynch_wakeup_this_sleeper(&register_synch, sleeper);
                        ++cnt;
                }
@@ -731,8 +738,8 @@ EXPORT_SYMBOL_GPL(xnregistry_enter);
 int xnregistry_bind(const char *key, xnticks_t timeout, int timeout_mode,
                    xnhandle_t *phandle)
 {
+       struct registry_wait_context rwc;
        struct xnobject *object;
-       struct xnthread *thread;
        int ret = 0, info;
        spl_t s;
 
@@ -760,8 +767,8 @@ int xnregistry_bind(const char *key, xnticks_t timeout, int 
timeout_mode,
                        goto unlock_and_exit;
                }
 
-               thread = xnthread_current();
-               thread->waitkey = key;
+               rwc.key = key;
+               xnthread_prepare_wait(&rwc.wc);
                info = xnsynch_sleep_on(&register_synch, timeout, timeout_mode);
                if (info & XNTIMEO) {
                        ret = -ETIMEDOUT;
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 5fb2de1..7c2405a 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -180,7 +180,6 @@ int __xnthread_init(struct xnthread *thread,
        thread->wcontext = NULL;
        thread->res_count = 0;
        thread->handle = XN_NO_HANDLE;
-       thread->waitkey = NULL;
        memset(&thread->stat, 0, sizeof(thread->stat));
        thread->selector = NULL;
        INIT_LIST_HEAD(&thread->claimq);


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

Reply via email to