Module: xenomai-3
Branch: master
Commit: 970053aa1dcad91aba28cb850b3be7df6cd46645
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=970053aa1dcad91aba28cb850b3be7df6cd46645

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Mar 18 18:51:41 2015 +0100

cobalt/posix/monitor: use resource management API

---

 kernel/cobalt/posix/monitor.c |   68 ++++++++++++-----------------------------
 kernel/cobalt/posix/monitor.h |    8 ++---
 kernel/cobalt/posix/process.c |    2 +-
 3 files changed, 25 insertions(+), 53 deletions(-)

diff --git a/kernel/cobalt/posix/monitor.c b/kernel/cobalt/posix/monitor.c
index 4e19af4..e928eeb 100644
--- a/kernel/cobalt/posix/monitor.c
+++ b/kernel/cobalt/posix/monitor.c
@@ -54,7 +54,6 @@ COBALT_SYSCALL(monitor_init, current,
 {
        struct cobalt_monitor_shadow shadow;
        struct cobalt_monitor_state *state;
-       struct cobalt_resources *rs;
        struct cobalt_monitor *mon;
        int pshared, tmode, ret;
        struct cobalt_umm *umm;
@@ -77,7 +76,7 @@ COBALT_SYSCALL(monitor_init, current,
                return -EAGAIN;
        }
 
-       ret = xnregistry_enter_anon(mon, &mon->handle);
+       ret = xnregistry_enter_anon(mon, &mon->resnode.handle);
        if (ret) {
                cobalt_umm_free(umm, state);
                xnfree(mon);
@@ -90,20 +89,17 @@ COBALT_SYSCALL(monitor_init, current,
        mon->flags = flags;
        mon->tmode = tmode;
        INIT_LIST_HEAD(&mon->waiters);
-       rs = cobalt_current_resources(pshared);
-       mon->scope = rs;
 
        xnlock_get_irqsave(&nklock, s);
-       list_add_tail(&mon->link, &rs->monitorq);
-       xnlock_put_irqrestore(&nklock, s);
-
+       cobalt_add_resource(&mon->resnode, monitor, pshared);
        mon->magic = COBALT_MONITOR_MAGIC;
+       xnlock_put_irqrestore(&nklock, s);
 
        state->flags = 0;
        stateoff = cobalt_umm_offset(umm, state);
        XENO_BUG_ON(COBALT, stateoff != (__u32)stateoff);
        shadow.flags = flags;
-       shadow.handle = mon->handle;
+       shadow.handle = mon->resnode.handle;
        shadow.state_offset = (__u32)stateoff;
 
        return cobalt_copy_to_user(u_mon, &shadow, sizeof(*u_mon));
@@ -376,25 +372,6 @@ COBALT_SYSCALL(monitor_exit, primary,
        return ret;
 }
 
-static void monitor_destroy(struct cobalt_monitor *mon)
-{
-       struct cobalt_umm *umm;
-       int pshared;
-       spl_t s;
-
-       xnlock_get_irqsave(&nklock, s);
-       list_del(&mon->link);
-       xnsynch_destroy(&mon->gate);
-       xnsynch_destroy(&mon->drain);
-       xnregistry_remove(mon->handle);
-       xnlock_put_irqrestore(&nklock, s);
-
-       pshared = (mon->flags & COBALT_MONITOR_SHARED) != 0;
-       umm = &cobalt_ppd_get(pshared)->umm;
-       cobalt_umm_free(umm, mon->state);
-       xnfree(mon);
-}
-
 COBALT_SYSCALL(monitor_destroy, primary,
               (struct cobalt_monitor_shadow __user *u_mon))
 {
@@ -432,11 +409,7 @@ COBALT_SYSCALL(monitor_destroy, primary,
                goto fail;
        }
 
-       mon->magic = 0; /* Hide it from userland before deletion. */
-
-       xnlock_put_irqrestore(&nklock, s);
-
-       monitor_destroy(mon);
+       cobalt_monitor_reclaim(&mon->resnode, s); /* drops lock */
 
        xnsched_run();
 
@@ -447,23 +420,22 @@ COBALT_SYSCALL(monitor_destroy, primary,
        return ret;
 }
 
-void cobalt_monitor_reclaim(struct cobalt_process *process)
+void cobalt_monitor_reclaim(struct cobalt_resnode *node, spl_t s)
 {
-       struct cobalt_resources *p = &process->resources;
-       struct cobalt_monitor *mon, *tmp;
-       spl_t s;
-
-       xnlock_get_irqsave(&nklock, s);
-
-       if (list_empty(&p->monitorq))
-               goto out;
+       struct cobalt_monitor *mon;
+       struct cobalt_umm *umm;
+       int pshared;
 
-       list_for_each_entry_safe(mon, tmp, &p->monitorq, link) {
-               mon->magic = 0;
-               xnlock_put_irqrestore(&nklock, s);
-               monitor_destroy(mon);
-               xnlock_get_irqsave(&nklock, s);
-       }
-out:
+       mon = container_of(node, struct cobalt_monitor, resnode);
+       pshared = (mon->flags & COBALT_MONITOR_SHARED) != 0;
+       xnsynch_destroy(&mon->gate);
+       xnsynch_destroy(&mon->drain);
+       xnregistry_remove(node->handle);
+       cobalt_del_resource(node);
+       cobalt_mark_deleted(mon);
        xnlock_put_irqrestore(&nklock, s);
+
+       umm = &cobalt_ppd_get(pshared)->umm;
+       cobalt_umm_free(umm, mon->state);
+       xnfree(mon);
 }
diff --git a/kernel/cobalt/posix/monitor.h b/kernel/cobalt/posix/monitor.h
index 80cafbb..8b321aa 100644
--- a/kernel/cobalt/posix/monitor.h
+++ b/kernel/cobalt/posix/monitor.h
@@ -22,6 +22,7 @@
 #include <cobalt/kernel/synch.h>
 #include <cobalt/uapi/monitor.h>
 #include <xenomai/posix/syscall.h>
+#include <xenomai/posix/process.h>
 
 struct cobalt_resources;
 struct cobalt_process;
@@ -31,12 +32,10 @@ struct cobalt_monitor {
        struct xnsynch gate;
        struct xnsynch drain;
        struct cobalt_monitor_state *state;
-       struct cobalt_resources *scope;
-       struct list_head link;
        struct list_head waiters;
        int flags;
        xntmode_t tmode;
-       xnhandle_t handle;
+       struct cobalt_resnode resnode;
 };
 
 int __cobalt_monitor_wait(struct cobalt_monitor_shadow __user *u_mon,
@@ -65,6 +64,7 @@ COBALT_SYSCALL_DECL(monitor_wait,
 COBALT_SYSCALL_DECL(monitor_destroy,
                    (struct cobalt_monitor_shadow __user *u_monsh));
 
-void cobalt_monitor_reclaim(struct cobalt_process *process);
+void cobalt_monitor_reclaim(struct cobalt_resnode *node,
+                           spl_t s);
 
 #endif /* !_COBALT_POSIX_MONITOR_H */
diff --git a/kernel/cobalt/posix/process.c b/kernel/cobalt/posix/process.c
index 31c5d7c..f473dc1 100644
--- a/kernel/cobalt/posix/process.c
+++ b/kernel/cobalt/posix/process.c
@@ -1407,10 +1407,10 @@ static void cobalt_process_detach(void *arg)
        cobalt_reclaim_resource(process, cobalt_cond_reclaim, cond);
        cobalt_reclaim_resource(process, cobalt_mutex_reclaim, mutex);
        cobalt_reclaim_resource(process, cobalt_event_reclaim, event);
+       cobalt_reclaim_resource(process, cobalt_monitor_reclaim, monitor);
        cobalt_nsem_reclaim(process);
        cobalt_timer_reclaim(process);
        cobalt_sem_reclaim(process);
-       cobalt_monitor_reclaim(process);
        cobalt_sched_reclaim(process);
        detach_process(process);
        /*


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

Reply via email to