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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Feb 19 17:01:14 2014 +0100

cobalt/registry: unify lookup calls

---

 include/cobalt/kernel/registry.h |   16 +++++++++++++---
 kernel/cobalt/posix/cond.c       |   14 +++++++-------
 kernel/cobalt/posix/event.c      |    6 +++---
 kernel/cobalt/posix/monitor.c    |   12 ++++++------
 kernel/cobalt/posix/mutex.c      |   16 +++++++++-------
 kernel/cobalt/posix/nsem.c       |    2 +-
 kernel/cobalt/posix/sem.c        |   16 ++++++++--------
 kernel/cobalt/registry.c         |   29 +++++++----------------------
 kernel/drivers/ipc/bufp.c        |    2 +-
 kernel/drivers/ipc/iddp.c        |    2 +-
 kernel/drivers/ipc/xddp.c        |    2 +-
 11 files changed, 57 insertions(+), 60 deletions(-)

diff --git a/include/cobalt/kernel/registry.h b/include/cobalt/kernel/registry.h
index ad1b84a..9c80352 100644
--- a/include/cobalt/kernel/registry.h
+++ b/include/cobalt/kernel/registry.h
@@ -177,10 +177,20 @@ int xnregistry_bind(const char *key,
 
 int xnregistry_remove(xnhandle_t handle);
 
-void *xnregistry_fetch(xnhandle_t handle);
-
+static inline
 void *xnregistry_lookup(xnhandle_t handle,
-                       unsigned long *cstamp_r);
+                       unsigned long *cstamp_r)
+{
+       struct xnobject *object = xnregistry_validate(handle);
+
+       if (object == NULL)
+               return NULL;
+
+       if (cstamp_r)
+               *cstamp_r = object->cstamp;
+
+       return object->objaddr;
+}
 
 int xnregistry_unlink(const char *key);
 
diff --git a/kernel/cobalt/posix/cond.c b/kernel/cobalt/posix/cond.c
index 9051f2a..3c22de2 100644
--- a/kernel/cobalt/posix/cond.c
+++ b/kernel/cobalt/posix/cond.c
@@ -60,7 +60,7 @@ cond_destroy_internal(xnhandle_t handle, struct 
cobalt_kqueues *q)
        spl_t s;
 
        xnlock_get_irqsave(&nklock, s);
-       cond = xnregistry_fetch(handle);
+       cond = xnregistry_lookup(handle, NULL);
        if (!cobalt_obj_active(cond, COBALT_COND_MAGIC, typeof(*cond))) {
                xnlock_put_irqrestore(&nklock, s);
                return;
@@ -147,7 +147,7 @@ pthread_cond_init(struct cobalt_cond_shadow *cnd, const 
pthread_condattr_t *attr
        if (cnd->magic != COBALT_COND_MAGIC || list_empty(condq))
                goto do_init;
 
-       old_cond = xnregistry_fetch(cnd->handle);
+       old_cond = xnregistry_lookup(cnd->handle, NULL);
        if (!cobalt_obj_active(old_cond, COBALT_COND_MAGIC, typeof(*old_cond)))
                goto do_init;
 
@@ -221,7 +221,7 @@ static inline int pthread_cond_destroy(struct 
cobalt_cond_shadow *cnd)
        spl_t s;
 
        xnlock_get_irqsave(&nklock, s);
-       cond = xnregistry_fetch(cnd->handle);
+       cond = xnregistry_lookup(cnd->handle, NULL);
        if (cond == NULL) {
                xnlock_put_irqrestore(&nklock, s);
                return -EINVAL;
@@ -420,10 +420,10 @@ int cobalt_cond_wait_prologue(struct cobalt_cond_shadow 
__user *u_cnd,
        int err, perr = 0;
 
        __xn_get_user(handle, &u_cnd->handle);
-       cnd = xnregistry_fetch(handle);
+       cnd = xnregistry_lookup(handle, NULL);
 
        __xn_get_user(handle, &u_mx->handle);
-       mx = xnregistry_fetch(handle);
+       mx = xnregistry_lookup(handle, NULL);
 
        if (!cnd->mutex) {
                __xn_get_user(datp, &u_mx->dat);
@@ -480,10 +480,10 @@ int cobalt_cond_wait_epilogue(struct cobalt_cond_shadow 
__user *u_cnd,
        int err;
 
        __xn_get_user(handle, &u_cnd->handle);
-       cnd = xnregistry_fetch(handle);
+       cnd = xnregistry_lookup(handle, NULL);
 
        __xn_get_user(handle, &u_mx->handle);
-       mx = xnregistry_fetch(handle);
+       mx = xnregistry_lookup(handle, NULL);
 
        err = cobalt_cond_timedwait_epilogue(cur, cnd, mx);
 
diff --git a/kernel/cobalt/posix/event.c b/kernel/cobalt/posix/event.c
index 3172a26..ebce65f 100644
--- a/kernel/cobalt/posix/event.c
+++ b/kernel/cobalt/posix/event.c
@@ -137,7 +137,7 @@ int cobalt_event_wait(struct cobalt_event_shadow __user 
*u_event,
 
        xnlock_get_irqsave(&nklock, s);
 
-       event = xnregistry_fetch(handle);
+       event = xnregistry_lookup(handle, NULL);
        if (event == NULL || event->magic != COBALT_EVENT_MAGIC) {
                ret = -EINVAL;
                goto out;
@@ -208,7 +208,7 @@ int cobalt_event_sync(struct cobalt_event_shadow __user 
*u_event)
 
        xnlock_get_irqsave(&nklock, s);
 
-       event = xnregistry_fetch(handle);
+       event = xnregistry_lookup(handle, NULL);
        if (event == NULL || event->magic != COBALT_EVENT_MAGIC) {
                ret = -EINVAL;
                goto out;
@@ -272,7 +272,7 @@ int cobalt_event_destroy(struct cobalt_event_shadow __user 
*u_event)
 
        xnlock_get_irqsave(&nklock, s);
 
-       event = xnregistry_fetch(handle);
+       event = xnregistry_lookup(handle, NULL);
        if (event == NULL || event->magic != COBALT_EVENT_MAGIC) {
                ret = -EINVAL;
                goto out;
diff --git a/kernel/cobalt/posix/monitor.c b/kernel/cobalt/posix/monitor.c
index a67b0e6..fd7c4fe 100644
--- a/kernel/cobalt/posix/monitor.c
+++ b/kernel/cobalt/posix/monitor.c
@@ -120,7 +120,7 @@ static int cobalt_monitor_enter_inner(xnhandle_t handle)
        struct cobalt_monitor *mon;
        int ret = 0, info;
 
-       mon = xnregistry_fetch(handle); /* (Re)validate. */
+       mon = xnregistry_lookup(handle, NULL); /* (Re)validate. */
        if (mon == NULL || mon->magic != COBALT_MONITOR_MAGIC)
                return -EINVAL;
 
@@ -253,7 +253,7 @@ int cobalt_monitor_wait(struct cobalt_monitor_shadow __user 
*u_mon,
 
        xnlock_get_irqsave(&nklock, s);
 
-       mon = xnregistry_fetch(handle);
+       mon = xnregistry_lookup(handle, NULL);
        if (mon == NULL || mon->magic != COBALT_MONITOR_MAGIC) {
                ret = -EINVAL;
                goto out;
@@ -285,7 +285,7 @@ int cobalt_monitor_wait(struct cobalt_monitor_shadow __user 
*u_mon,
        info = xnsynch_sleep_on(synch, timeout, tmode);
        if (info) {
                if ((info & XNRMID) != 0 ||
-                   xnregistry_fetch(handle) != mon /* XXX: why this? */) {
+                   xnregistry_lookup(handle, NULL) != mon /* XXX: why this? 
*/) {
                        ret = -EINVAL;
                        goto out;
                }
@@ -325,7 +325,7 @@ int cobalt_monitor_sync(struct cobalt_monitor_shadow __user 
*u_mon)
 
        xnlock_get_irqsave(&nklock, s);
 
-       mon = xnregistry_fetch(handle);
+       mon = xnregistry_lookup(handle, NULL);
        if (mon == NULL || mon->magic != COBALT_MONITOR_MAGIC)
                ret = -EINVAL;
        else if (mon->data->flags & COBALT_MONITOR_SIGNALED) {
@@ -351,7 +351,7 @@ int cobalt_monitor_exit(struct cobalt_monitor_shadow __user 
*u_mon)
 
        xnlock_get_irqsave(&nklock, s);
 
-       mon = xnregistry_fetch(handle);
+       mon = xnregistry_lookup(handle, NULL);
        if (mon == NULL || mon->magic != COBALT_MONITOR_MAGIC)
                ret = -EINVAL;
        else {
@@ -399,7 +399,7 @@ int cobalt_monitor_destroy(struct cobalt_monitor_shadow 
__user *u_mon)
 
        xnlock_get_irqsave(&nklock, s);
 
-       mon = xnregistry_fetch(handle);
+       mon = xnregistry_lookup(handle, NULL);
        if (mon == NULL || mon->magic != COBALT_MONITOR_MAGIC) {
                ret = -EINVAL;
                goto fail;
diff --git a/kernel/cobalt/posix/mutex.c b/kernel/cobalt/posix/mutex.c
index 9c66a3c..99a7e64 100644
--- a/kernel/cobalt/posix/mutex.c
+++ b/kernel/cobalt/posix/mutex.c
@@ -108,7 +108,7 @@ cobalt_mutex_destroy_inner(xnhandle_t handle, struct 
cobalt_kqueues *q)
        spl_t s;
 
        xnlock_get_irqsave(&nklock, s);
-       mutex = xnregistry_fetch(handle);
+       mutex = xnregistry_lookup(handle, NULL);
        if (!cobalt_obj_active(mutex, COBALT_MUTEX_MAGIC, typeof(*mutex))) {
                xnlock_put_irqrestore(&nklock, s);
                printk("mutex_destroy: invalid mutex %x\n", 
@@ -262,7 +262,7 @@ int cobalt_mutex_check_init(struct cobalt_mutex_shadow 
__user *u_mx)
        __xn_get_user(handle, &u_mx->handle);
 
        xnlock_get_irqsave(&nklock, s);
-       mutex = xnregistry_fetch(handle);
+       mutex = xnregistry_lookup(handle, NULL);
        if (cobalt_obj_active(mutex, COBALT_MUTEX_MAGIC, typeof(*mutex)))
                /* mutex is already in a queue. */
                err = -EBUSY;
@@ -327,7 +327,7 @@ int cobalt_mutex_destroy(struct cobalt_mutex_shadow __user 
*u_mx)
                return -EFAULT;
 
        xnlock_get_irqsave(&nklock, s);
-       mutex = xnregistry_fetch(mx.handle);
+       mutex = xnregistry_lookup(mx.handle, NULL);
        if (!cobalt_obj_active(mutex, COBALT_MUTEX_MAGIC, typeof(*mutex))) {
                err = -EINVAL;
                goto err_unlock;
@@ -368,7 +368,7 @@ int cobalt_mutex_trylock(struct cobalt_mutex_shadow __user 
*u_mx)
        __xn_get_user(handle, &u_mx->handle);
 
        xnlock_get_irqsave(&nklock, s);
-       mutex = xnregistry_fetch(handle);
+       mutex = xnregistry_lookup(handle, NULL);
        if (!cobalt_obj_active(mutex, COBALT_MUTEX_MAGIC, typeof(*mutex))) {
                err = -EINVAL;
                goto err_unlock;
@@ -407,7 +407,8 @@ int cobalt_mutex_lock(struct cobalt_mutex_shadow __user 
*u_mx)
        __xn_get_user(handle, &u_mx->handle);
 
        xnlock_get_irqsave(&nklock, s);
-       err = cobalt_mutex_timedlock_break(xnregistry_fetch(handle), 0, NULL);
+       err = cobalt_mutex_timedlock_break(xnregistry_lookup(handle, NULL),
+                                          0, NULL);
        xnlock_put_irqrestore(&nklock, s);
        
        return err;
@@ -423,7 +424,8 @@ int cobalt_mutex_timedlock(struct cobalt_mutex_shadow 
__user *u_mx,
        __xn_get_user(handle, &u_mx->handle);
 
        xnlock_get_irqsave(&nklock, s);
-       err = cobalt_mutex_timedlock_break(xnregistry_fetch(handle), 1, u_ts);
+       err = cobalt_mutex_timedlock_break(xnregistry_lookup(handle, NULL),
+                                          1, u_ts);
        xnlock_put_irqrestore(&nklock, s);
 
        return err;
@@ -440,7 +442,7 @@ int cobalt_mutex_unlock(struct cobalt_mutex_shadow __user 
*u_mx)
        __xn_get_user(handle, &u_mx->handle);
 
        xnlock_get_irqsave(&nklock, s);
-       mutex = xnregistry_fetch(handle);
+       mutex = xnregistry_lookup(handle, NULL);
        err = cobalt_mutex_release(xnsched_current_thread(), mutex);
        if (err < 0)
                goto out;
diff --git a/kernel/cobalt/posix/nsem.c b/kernel/cobalt/posix/nsem.c
index 75dbec3..346585f 100644
--- a/kernel/cobalt/posix/nsem.c
+++ b/kernel/cobalt/posix/nsem.c
@@ -77,7 +77,7 @@ nsem_open(struct cobalt_process *cc, struct cobalt_sem_shadow 
__user *ushadow,
                xnlock_put_irqrestore(&nsem_lock, s);
 
                xnlock_get_irqsave(&nklock, s);
-               sem = xnregistry_fetch(handle);
+               sem = xnregistry_lookup(handle, NULL);
                if (sem && sem->magic != COBALT_SEM_MAGIC) {
                        xnlock_put_irqrestore(&nklock, s);
                        return ERR_PTR(-EINVAL);
diff --git a/kernel/cobalt/posix/sem.c b/kernel/cobalt/posix/sem.c
index ba729e7..7321d9c 100644
--- a/kernel/cobalt/posix/sem.c
+++ b/kernel/cobalt/posix/sem.c
@@ -53,7 +53,7 @@ int cobalt_sem_destroy_inner(xnhandle_t handle)
        spl_t s;
 
        xnlock_get_irqsave(&nklock, s);
-       sem = xnregistry_fetch(handle);
+       sem = xnregistry_lookup(handle, NULL);
        if (!cobalt_obj_active(sem, COBALT_SEM_MAGIC, typeof(*sem))) {
                ret = -EINVAL;
                goto unlock_error;
@@ -127,7 +127,7 @@ cobalt_sem_init_inner(const char *name, struct 
cobalt_sem_shadow *sm,
         * such semaphore exits, we may assume that other processes
         * sharing that semaphore won't be able to keep on running.
         */
-       osem = xnregistry_fetch(sm->handle);
+       osem = xnregistry_lookup(sm->handle, NULL);
        if (!cobalt_obj_active(osem, COBALT_SEM_MAGIC, typeof(*osem)))
                goto do_init;
 
@@ -223,7 +223,7 @@ static int sem_destroy(struct cobalt_sem_shadow *sm)
                goto error;
        }
 
-       sem = xnregistry_fetch(sm->handle);
+       sem = xnregistry_lookup(sm->handle, NULL);
        if (!cobalt_obj_active(sem, COBALT_SEM_MAGIC, typeof(*sem))) {
                ret = -EINVAL;
                goto error;
@@ -392,7 +392,7 @@ static int sem_trywait(xnhandle_t handle)
        spl_t s;
 
        xnlock_get_irqsave(&nklock, s);
-       err = sem_trywait_inner(xnregistry_fetch(handle));
+       err = sem_trywait_inner(xnregistry_lookup(handle, NULL));
        xnlock_put_irqrestore(&nklock, s);
 
        return err;
@@ -410,7 +410,7 @@ sem_wait_inner(xnhandle_t handle, int timed,
 
        xnlock_get_irqsave(&nklock, s);
 
-       sem = xnregistry_fetch(handle);
+       sem = xnregistry_lookup(handle, NULL);
 
        ret = sem_trywait_inner(sem);
        if (ret != -EAGAIN) {
@@ -593,7 +593,7 @@ static int sem_post(xnhandle_t handle)
        spl_t s;
 
        xnlock_get_irqsave(&nklock, s);
-       sm = xnregistry_fetch(handle);
+       sm = xnregistry_lookup(handle, NULL);
        ret = sem_post_inner(sm, sm->owningq, 0);
        xnlock_put_irqrestore(&nklock, s);
 
@@ -635,7 +635,7 @@ static int sem_getvalue(xnhandle_t handle, int *value)
 
        xnlock_get_irqsave(&nklock, s);
 
-       sem = xnregistry_fetch(handle);
+       sem = xnregistry_lookup(handle, NULL);
 
        if (sem == NULL || sem->magic != COBALT_SEM_MAGIC) {
                xnlock_put_irqrestore(&nklock, s);
@@ -767,7 +767,7 @@ int cobalt_sem_broadcast_np(struct cobalt_sem_shadow __user 
*u_sem)
        __xn_get_user(handle, &u_sem->handle);
 
        xnlock_get_irqsave(&nklock, s);
-       sm = xnregistry_fetch(handle);
+       sm = xnregistry_lookup(handle, NULL);
        err = sem_post_inner(sm, sm->owningq, 1);
        xnlock_put_irqrestore(&nklock, s);
 
diff --git a/kernel/cobalt/registry.c b/kernel/cobalt/registry.c
index 5d8bcf7..47d5451 100644
--- a/kernel/cobalt/registry.c
+++ b/kernel/cobalt/registry.c
@@ -897,40 +897,25 @@ unlock_and_exit:
        return ret;
 }
 
-void *xnregistry_lookup(xnhandle_t handle,
-                       unsigned long *cstamp_r)
-{
-       struct xnobject *object = xnregistry_validate(handle);
-
-       if (object == NULL)
-               return NULL;
-
-       if (cstamp_r)
-               *cstamp_r = object->cstamp;
-
-       return object->objaddr;
-}
-EXPORT_SYMBOL_GPL(xnregistry_lookup);
-
 /**
- * @fn void *xnregistry_fetch(xnhandle_t handle)
+ * @fn void *xnregistry_lookup(xnhandle_t handle, unsigned long *cstamp_r)
  * @brief Find a real-time object into the registry.
  *
  * This service retrieves an object from its handle into the registry
- * and returns the memory address of its descriptor.
+ * and returns the memory address of its descriptor. Optionally, it
+ * also copies back the object's creation stamp which is unique across
+ * object registration calls.
  *
  * @param handle The generic handle of the object to fetch.
  *
+ * @param cstamp_r If not-NULL, the object's creation stamp will be
+ * copied to this memory area.
+ *
  * @return The memory address of the object's descriptor is returned
  * on success. Otherwise, NULL is returned if @a handle does not
  * reference a registered object.
  *
  * @remark Tags: isr-allowed.
  */
-void *xnregistry_fetch(xnhandle_t handle)
-{
-       return xnregistry_lookup(handle, NULL);
-}
-EXPORT_SYMBOL_GPL(xnregistry_fetch);
 
 /*@}*/
diff --git a/kernel/drivers/ipc/bufp.c b/kernel/drivers/ipc/bufp.c
index 233d86a..4363c68 100644
--- a/kernel/drivers/ipc/bufp.c
+++ b/kernel/drivers/ipc/bufp.c
@@ -773,7 +773,7 @@ static int __bufp_connect_socket(struct bufp_socket *sk,
                        return ret;
 
                RTDM_EXECUTE_ATOMICALLY(
-                       rsk = xnregistry_fetch(h);
+                       rsk = xnregistry_lookup(h, NULL);
                        if (rsk == NULL || rsk->magic != BUFP_SOCKET_MAGIC)
                                ret = -EINVAL;
                        else
diff --git a/kernel/drivers/ipc/iddp.c b/kernel/drivers/ipc/iddp.c
index c066d4d..3fe43db 100644
--- a/kernel/drivers/ipc/iddp.c
+++ b/kernel/drivers/ipc/iddp.c
@@ -656,7 +656,7 @@ static int __iddp_connect_socket(struct iddp_socket *sk,
                        return ret;
 
                RTDM_EXECUTE_ATOMICALLY(
-                       rsk = xnregistry_fetch(h);
+                       rsk = xnregistry_lookup(h, NULL);
                        if (rsk == NULL || rsk->magic != IDDP_SOCKET_MAGIC)
                                ret = -EINVAL;
                        else
diff --git a/kernel/drivers/ipc/xddp.c b/kernel/drivers/ipc/xddp.c
index 23d2acf..728a6ed 100644
--- a/kernel/drivers/ipc/xddp.c
+++ b/kernel/drivers/ipc/xddp.c
@@ -803,7 +803,7 @@ static int __xddp_connect_socket(struct xddp_socket *sk,
                        return ret;
 
                RTDM_EXECUTE_ATOMICALLY(
-                       rsk = xnregistry_fetch(h);
+                       rsk = xnregistry_lookup(h, NULL);
                        if (rsk == NULL || rsk->magic != XDDP_SOCKET_MAGIC)
                                ret = -EINVAL;
                        else


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

Reply via email to