Module: xenomai-jki
Branch: for-forge
Commit: 3c6a48e0eae6a1b656d18dcbe1dd96f3563bcf7a
URL:    
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=3c6a48e0eae6a1b656d18dcbe1dd96f3563bcf7a

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Mon May  9 21:19:04 2016 +0200

cobalt/kernel: Return need_resched flag from xnsynch_release

We currently return the next owner, but no caller of xnsynch_release
evaluates this beyond != NULL and calls xnsched_run in that case.
Simplify the API by returning a need_resched flag directly. This will
also help with fixing the missing reschedule after PP deboost.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 include/cobalt/kernel/synch.h |    3 +--
 kernel/cobalt/posix/mutex.c   |    2 +-
 kernel/cobalt/rtdm/drvlib.c   |    2 +-
 kernel/cobalt/synch.c         |   23 +++++++++++------------
 4 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/include/cobalt/kernel/synch.h b/include/cobalt/kernel/synch.h
index 04d7f10..1e99c18 100644
--- a/include/cobalt/kernel/synch.h
+++ b/include/cobalt/kernel/synch.h
@@ -164,8 +164,7 @@ int xnsynch_acquire(struct xnsynch *synch,
 
 int xnsynch_try_acquire(struct xnsynch *synch);
 
-struct xnthread *xnsynch_release(struct xnsynch *synch,
-                                struct xnthread *thread);
+bool xnsynch_release(struct xnsynch *synch, struct xnthread *thread);
 
 struct xnthread *xnsynch_peek_pendq(struct xnsynch *synch);
 
diff --git a/kernel/cobalt/posix/mutex.c b/kernel/cobalt/posix/mutex.c
index c6020ff..f99874b 100644
--- a/kernel/cobalt/posix/mutex.c
+++ b/kernel/cobalt/posix/mutex.c
@@ -128,7 +128,7 @@ int cobalt_mutex_release(struct xnthread *curr,
                                cobalt_cond_deferred_signals(cond);
                }
        }
-       need_resched |= xnsynch_release(&mutex->synchbase, curr) != NULL;
+       need_resched |= xnsynch_release(&mutex->synchbase, curr);
 
        return need_resched;
 }
diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index ae55a4b..1973c37 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -1282,7 +1282,7 @@ void rtdm_mutex_unlock(rtdm_mutex_t *mutex)
        trace_cobalt_driver_mutex_release(mutex);
 
        if (unlikely(xnsynch_release(&mutex->synch_base,
-                                    xnsched_current_thread()) != NULL))
+                                    xnsched_current_thread())))
                xnsched_run();
 }
 EXPORT_SYMBOL_GPL(rtdm_mutex_unlock);
diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index 976261d..0130844 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -843,8 +843,8 @@ static inline void clear_pp_boost(struct xnsynch *synch,
        drop_booster(synch, owner);
 }
 
-static struct xnthread *transfer_ownership(struct xnsynch *synch,
-                                          struct xnthread *lastowner)
+static bool transfer_ownership(struct xnsynch *synch,
+                              struct xnthread *lastowner)
 {                              /* nklock held, irqs off */
        struct xnthread *nextowner;
        xnhandle_t nextownerh;
@@ -859,7 +859,7 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
        if (list_empty(&synch->pendq)) {
                synch->owner = NULL;
                atomic_set(lockp, XN_NO_HANDLE);
-               return NULL;
+               return false;
        }
 
        nextowner = list_first_entry(&synch->pendq, struct xnthread, plink);
@@ -879,11 +879,11 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
 
        atomic_set(lockp, nextownerh);
 
-       return nextowner;
+       return true;
 }
 
 /**
- * @fn struct xnthread *xnsynch_release(struct xnsynch *synch, struct xnthread 
*curr)
+ * @fn bool xnsynch_release(struct xnsynch *synch, struct xnthread *curr)
  * @brief Release a resource and pass it to the next waiting thread.
  *
  * This service releases the ownership of the given synchronization
@@ -900,7 +900,7 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
  * @param curr The descriptor address of the current thread, which
  * must own the object at the time of calling.
  *
- * @return The descriptor address of the unblocked thread.
+ * @return True if a reschedule is required.
  *
  * @sideeffect
  *
@@ -913,10 +913,9 @@ static struct xnthread *transfer_ownership(struct xnsynch 
*synch,
  *
  * @coretags{primary-only, might-switch}
  */
-struct xnthread *xnsynch_release(struct xnsynch *synch,
-                                struct xnthread *curr)
+bool xnsynch_release(struct xnsynch *synch, struct xnthread *curr)
 {
-       struct xnthread *nextowner = NULL;
+       bool need_resched = false;
        xnhandle_t currh, h;
        atomic_t *lockp;
        spl_t s;
@@ -926,7 +925,7 @@ struct xnthread *xnsynch_release(struct xnsynch *synch,
        trace_cobalt_synch_release(synch);
 
        if (xnthread_put_resource(curr))
-               return NULL;
+               return 0;
 
        lockp = xnsynch_fastlock(synch);
        currh = curr->handle;
@@ -946,7 +945,7 @@ struct xnthread *xnsynch_release(struct xnsynch *synch,
        h = atomic_cmpxchg(lockp, currh, XN_NO_HANDLE);
        if ((h & ~XNSYNCH_FLCEIL) != currh)
                /* FLCLAIM set, synch is contended. */
-               nextowner = transfer_ownership(synch, curr);
+               need_resched = transfer_ownership(synch, curr);
        else if (h != currh)    /* FLCEIL set, FLCLAIM clear. */
                atomic_set(lockp, XN_NO_HANDLE);
 
@@ -955,7 +954,7 @@ struct xnthread *xnsynch_release(struct xnsynch *synch,
 
        xnlock_put_irqrestore(&nklock, s);
 
-       return nextowner;
+       return need_resched;
 }
 EXPORT_SYMBOL_GPL(xnsynch_release);
 


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

Reply via email to