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

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Fri Jun 13 21:31:02 2014 +0200

cobalt/sem: fix named semaphore cleanup

---

 kernel/cobalt/posix/nsem.c |   24 ++++++++++++------------
 kernel/cobalt/posix/sem.c  |   16 +++++++---------
 kernel/cobalt/posix/sem.h  |    9 +++++----
 3 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/kernel/cobalt/posix/nsem.c b/kernel/cobalt/posix/nsem.c
index d99579a..3697005 100644
--- a/kernel/cobalt/posix/nsem.c
+++ b/kernel/cobalt/posix/nsem.c
@@ -39,16 +39,16 @@ struct named_sem {
 static struct named_sem *sem_search(struct cobalt_process *cc, xnhandle_t 
handle)
 {
        struct xnid *i;
-       
+
        i = xnid_fetch(&cc->usems, handle);
        if (i == NULL)
                return NULL;
-       
+
        return container_of(i, struct named_sem, id);
 }
 
 static struct cobalt_sem_shadow __user *
-sem_open(struct cobalt_process *cc, struct cobalt_sem_shadow __user *ushadow, 
+sem_open(struct cobalt_process *cc, struct cobalt_sem_shadow __user *ushadow,
         const char *name, int oflags, mode_t mode, unsigned int value)
 {
        struct cobalt_sem_shadow shadow;
@@ -84,7 +84,7 @@ sem_open(struct cobalt_process *cc, struct cobalt_sem_shadow 
__user *ushadow,
                        xnlock_put_irqrestore(&nklock, s);
                        return ERR_PTR(-EINVAL);
                }
-                       
+
                if (sem) {
                        ++sem->refs;
                        xnlock_put_irqrestore(&nklock, s);
@@ -93,7 +93,7 @@ sem_open(struct cobalt_process *cc, struct cobalt_sem_shadow 
__user *ushadow,
                        goto retry_bind;
                }
                break;
-               
+
        case -EWOULDBLOCK:
                /* Not found */
                if ((oflags & O_CREAT) == 0)
@@ -101,7 +101,7 @@ sem_open(struct cobalt_process *cc, struct 
cobalt_sem_shadow __user *ushadow,
 
                shadow.magic = 0;
                sem = cobalt_sem_init_inner
-                       (&name[1], &shadow, SEM_PSHARED, value);
+                       (&name[1], &shadow, SEM_PSHARED | SEM_NAMED, value);
                if (IS_ERR(sem)) {
                        rc = PTR_ERR(sem);
                        if (rc == -EEXIST)
@@ -121,7 +121,7 @@ sem_open(struct cobalt_process *cc, struct 
cobalt_sem_shadow __user *ushadow,
        }
 
        u = xnmalloc(sizeof(*u));
-       if (u == NULL) 
+       if (u == NULL)
                return ERR_PTR(-ENOMEM);
 
        u->sem = sem;
@@ -161,20 +161,20 @@ static int sem_close(struct cobalt_process *cc, 
xnhandle_t handle)
                err = -ENOENT;
                goto err_unlock;
        }
-       
+
        if (--u->refs) {
                err = 0;
                goto err_unlock;
        }
-       
+
        xnid_remove(&cc->usems, &u->id);
        xnlock_put_irqrestore(&named_sem_lock, s);
-                       
+
        cobalt_sem_destroy_inner(handle);
-       
+
        xnfree(u);
        return 1;
-       
+
   err_unlock:
        xnlock_put_irqrestore(&named_sem_lock, s);
        return err;
diff --git a/kernel/cobalt/posix/sem.c b/kernel/cobalt/posix/sem.c
index 76641cc..bd93a26 100644
--- a/kernel/cobalt/posix/sem.c
+++ b/kernel/cobalt/posix/sem.c
@@ -24,8 +24,6 @@
 #include "sem.h"
 #include <trace/events/cobalt-posix.h>
 
-#define SEM_NAMED    0x80000000
-
 static inline struct cobalt_kqueues *sem_kqueue(struct cobalt_sem *sem)
 {
        int pshared = !!(sem->flags & SEM_PSHARED);
@@ -57,20 +55,20 @@ int cobalt_sem_destroy_inner(xnhandle_t handle)
                xnsched_run();
                ret = 1;
        }
-       
+
        xnlock_put_irqrestore(&nklock, s);
 
        xnheap_free(&xnsys_ppd_get(!!(sem->flags & SEM_PSHARED))->sem_heap,
                sem->datp);
        xnregistry_remove(sem->handle);
-       
+
        xnfree(sem);
 
        return ret;
 }
 
 struct cobalt_sem *
-cobalt_sem_init_inner(const char *name, struct cobalt_sem_shadow *sm, 
+cobalt_sem_init_inner(const char *name, struct cobalt_sem_shadow *sm,
                      int flags, unsigned int value)
 {
        struct cobalt_sem *sem, *osem;
@@ -134,7 +132,7 @@ cobalt_sem_init_inner(const char *name, struct 
cobalt_sem_shadow *sm,
                ret = -EINVAL;
                goto err_lock_put;
        }
-       
+
        ret = xnregistry_enter(sem->name, sem, &sem->handle, NULL);
        if (ret < 0)
                goto err_lock_put;
@@ -150,7 +148,7 @@ cobalt_sem_init_inner(const char *name, struct 
cobalt_sem_shadow *sm,
        sem->flags = flags;
        sem->owningq = kq;
        sem->refs = name[0] ? 2 : 1;
-                       
+
        sm->magic = name[0] ? COBALT_NAMED_SEM_MAGIC : COBALT_SEM_MAGIC;
        sm->handle = sem->handle;
        sm->datp_offset = xnheap_mapped_offset(&sys_ppd->sem_heap, datp);
@@ -289,7 +287,7 @@ redo:
                tmode = sem->flags & SEM_RAWCLOCK ? XN_ABSOLUTE : XN_REALTIME;
                info = xnsynch_sleep_on(&sem->synchbase, ts2ns(&ts) + 1, tmode);
        } else
-               info = xnsynch_sleep_on(&sem->synchbase, 
+               info = xnsynch_sleep_on(&sem->synchbase,
                                        XN_INFINITE, XN_RELATIVE);
        if (info & XNRMID)
                goto einval;
@@ -346,7 +344,7 @@ int sem_post_inner(struct cobalt_sem *sem, struct 
cobalt_kqueues *ownq, int bcas
        } else {
                if (atomic_long_read(&sem->datp->value) < 0) {
                        atomic_long_set(&sem->datp->value, 0);
-                       if (xnsynch_flush(&sem->synchbase, 0) == 
+                       if (xnsynch_flush(&sem->synchbase, 0) ==
                                XNSYNCH_RESCHED)
                                xnsched_run();
                }
diff --git a/kernel/cobalt/posix/sem.h b/kernel/cobalt/posix/sem.h
index 41256dd..2612700 100644
--- a/kernel/cobalt/posix/sem.h
+++ b/kernel/cobalt/posix/sem.h
@@ -54,11 +54,12 @@ typedef struct
 
 #include <cobalt/uapi/sem.h>
 
-#define SEM_VALUE_MAX (INT_MAX)
-#define SEM_FAILED    NULL
+#define SEM_VALUE_MAX  (INT_MAX)
+#define SEM_FAILED     NULL
+#define SEM_NAMED      0x80000000
 
-struct cobalt_sem * 
-cobalt_sem_init_inner(const char *name, struct cobalt_sem_shadow *sem, 
+struct cobalt_sem *
+cobalt_sem_init_inner(const char *name, struct cobalt_sem_shadow *sem,
                int flags, unsigned value);
 
 int cobalt_sem_destroy_inner(xnhandle_t handle);


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

Reply via email to