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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Jul  3 12:28:37 2015 +0200

cobalt/sched: simplify locking helpers

---

 include/cobalt/kernel/sched.h |   36 ++++--------------------------------
 kernel/cobalt/sched.c         |   10 ----------
 kernel/cobalt/thread.c        |   11 +++++++----
 3 files changed, 11 insertions(+), 46 deletions(-)

diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h
index ca0f732..a215dd8 100644
--- a/include/cobalt/kernel/sched.h
+++ b/include/cobalt/kernel/sched.h
@@ -304,54 +304,31 @@ static inline void ___xnsched_lock(struct xnsched *sched)
 
 void ___xnsched_unlock(struct xnsched *sched);
 
-void ___xnsched_unlock_fully(struct xnsched *sched);
-
 static inline void __xnsched_lock(void)
 {
-       struct xnsched *sched;
-
-       barrier();
-       sched = xnsched_current();
-       ___xnsched_lock(sched);
+       ___xnsched_lock(xnsched_current());
 }
 
 static inline void __xnsched_unlock(void)
 {
-       struct xnsched *sched;
-
-       barrier();
-       sched = xnsched_current();
-       ___xnsched_unlock(sched);
-}
-
-static inline void __xnsched_unlock_fully(void)
-{
-       struct xnsched *sched;
-
-       barrier();
-       sched = xnsched_current();
-       ___xnsched_unlock_fully(sched);
+       ___xnsched_unlock(xnsched_current());
 }
 
 static inline void xnsched_lock(void)
 {
-       struct xnsched *sched;
        spl_t s;
 
        xnlock_get_irqsave(&nklock, s);
-       sched = xnsched_current();
-       ___xnsched_lock(sched);
+       __xnsched_lock();
        xnlock_put_irqrestore(&nklock, s);
 }
 
 static inline void xnsched_unlock(void)
 {
-       struct xnsched *sched;
        spl_t s;
 
        xnlock_get_irqsave(&nklock, s);
-       sched = xnsched_current();
-       ___xnsched_unlock(sched);
+       __xnsched_unlock();
        xnlock_put_irqrestore(&nklock, s);
 }
 
@@ -360,11 +337,6 @@ static inline int xnsched_interrupt_p(void)
        return xnsched_current()->lflags & XNINIRQ;
 }
 
-static inline int xnsched_locked_p(void)
-{
-       return xnsched_current_thread()->lock_count > 0;
-}
-
 static inline int xnsched_root_p(void)
 {
        return xnthread_test_state(xnsched_current_thread(), XNROOT);
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index b9eff80..d63927e 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -334,16 +334,6 @@ void ___xnsched_unlock(struct xnsched *sched)
 }
 EXPORT_SYMBOL_GPL(___xnsched_unlock);
 
-void ___xnsched_unlock_fully(struct xnsched *sched)
-{
-       struct xnthread *curr = sched->curr;
-
-       curr->lock_count = 0;
-       xnthread_clear_localinfo(curr, XNLBALERT);
-       xnsched_run();
-}
-EXPORT_SYMBOL_GPL(___xnsched_unlock_fully);
-
 /* Must be called with nklock locked, interrupts off. */
 void xnsched_putback(struct xnthread *thread)
 {
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 5b00ad1..3a5aa71 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -758,8 +758,11 @@ int xnthread_set_mode(int clrmask, int setmask)
                if (lock_count == 0)
                        __xnsched_lock();
        } else if (clrmask & XNLOCK) {
-               if (lock_count > 0)
-                       __xnsched_unlock_fully();
+               if (lock_count > 0) {
+                       curr->lock_count = 0;
+                       xnthread_clear_localinfo(curr, XNLBALERT);
+                       xnsched_run();
+               }
        }
 
        xnlock_put_irqrestore(&nklock, s);
@@ -1644,12 +1647,12 @@ int xnthread_migrate(int cpu)
 
        xnlock_get_irqsave(&nklock, s);
 
-       if (!xnsched_primary_p() || xnsched_locked_p()) {
+       curr = xnthread_current();
+       if (!xnsched_primary_p() || curr->lock_count > 0) {
                ret = -EPERM;
                goto unlock_and_exit;
        }
 
-       curr = xnthread_current();
        if (!cpu_isset(cpu, curr->affinity)) {
                ret = -EINVAL;
                goto unlock_and_exit;


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

Reply via email to