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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Jul 17 16:54:47 2015 +0200

cobalt/synch: test information bits as returned by xnsynch_sleep_on() only

For consistency with xnsynch_acquire(), callers of xnsynch_sleep_on()
MUST retrieve the information bits from the return value, instead of
peeking into the current thread's TCB.

---

 kernel/cobalt/posix/cond.c  |   14 +++++++-------
 kernel/cobalt/rtdm/drvlib.c |   38 ++++++++++++++++++--------------------
 kernel/cobalt/synch.c       |    2 +-
 3 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/kernel/cobalt/posix/cond.c b/kernel/cobalt/posix/cond.c
index 502df5d..7e115cf 100644
--- a/kernel/cobalt/posix/cond.c
+++ b/kernel/cobalt/posix/cond.c
@@ -125,8 +125,8 @@ static inline int cobalt_cond_timedwait_prologue(struct 
xnthread *cur,
                                                 struct cobalt_mutex *mutex,
                                                 xnticks_t abs_to)
 {
+       int err, ret;
        spl_t s;
-       int err;
 
        xnlock_get_irqsave(&nklock, s);
 
@@ -166,10 +166,10 @@ static inline int cobalt_cond_timedwait_prologue(struct 
xnthread *cur,
 
        /* Wait for another thread to signal the condition. */
        if (abs_to != XN_INFINITE)
-               xnsynch_sleep_on(&cond->synchbase, abs_to,
-                                clock_flag(TIMER_ABSTIME, cond->attr.clock));
+               ret = xnsynch_sleep_on(&cond->synchbase, abs_to,
+                                      clock_flag(TIMER_ABSTIME, 
cond->attr.clock));
        else
-               xnsynch_sleep_on(&cond->synchbase, XN_INFINITE, XN_RELATIVE);
+               ret = xnsynch_sleep_on(&cond->synchbase, XN_INFINITE, 
XN_RELATIVE);
 
        /* There are three possible wakeup conditions :
           - cond_signal / cond_broadcast, no status bit is set, and the 
function
@@ -185,12 +185,12 @@ static inline int cobalt_cond_timedwait_prologue(struct 
xnthread *cur,
 
        err = 0;
 
-       if (xnthread_test_info(cur, XNBREAK))
+       if (ret & XNBREAK)
                err = -EINTR;
-       else if (xnthread_test_info(cur, XNTIMEO))
+       else if (ret & XNTIMEO)
                err = -ETIMEDOUT;
 
-      unlock_and_return:
+unlock_and_return:
        xnlock_put_irqrestore(&nklock, s);
 
        return err;
diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index 6c4bc0d..ca46531 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -769,8 +769,8 @@ int rtdm_event_timedwait(rtdm_event_t *event, 
nanosecs_rel_t timeout,
                         rtdm_toseq_t *timeout_seq)
 {
        struct xnthread *thread;
+       int err = 0, ret;
        spl_t s;
-       int err = 0;
 
        if (!XENO_ASSERT(COBALT, !xnsched_unblockable_p()))
                return -EPERM;
@@ -793,23 +793,21 @@ int rtdm_event_timedwait(rtdm_event_t *event, 
nanosecs_rel_t timeout,
 
                thread = xnthread_current();
 
-               if (timeout_seq && (timeout > 0)) {
+               if (timeout_seq && (timeout > 0))
                        /* timeout sequence */
-                       xnsynch_sleep_on(&event->synch_base, *timeout_seq,
-                                        XN_ABSOLUTE);
-               } else {
+                       ret = xnsynch_sleep_on(&event->synch_base, *timeout_seq,
+                                              XN_ABSOLUTE);
+               else
                        /* infinite or relative timeout */
-                       xnsynch_sleep_on(&event->synch_base, timeout, 
XN_RELATIVE);
-               }
+                       ret = xnsynch_sleep_on(&event->synch_base, timeout, 
XN_RELATIVE);
 
-               if (likely
-                   (!xnthread_test_info(thread, XNTIMEO | XNRMID | XNBREAK))) {
+               if (likely(ret == 0)) {
                        xnsynch_clear_status(&event->synch_base,
                                            RTDM_EVENT_PENDING);
                        xnselect_signal(&event->select_block, 0);
-               } else if (xnthread_test_info(thread, XNTIMEO))
+               } else if (ret & XNTIMEO)
                        err = -ETIMEDOUT;
-               else if (xnthread_test_info(thread, XNRMID))
+               else if (ret & XNRMID)
                        err = -EIDRM;
                else /* XNBREAK */
                        err = -EINTR;
@@ -1004,8 +1002,8 @@ int rtdm_sem_timeddown(rtdm_sem_t *sem, nanosecs_rel_t 
timeout,
                       rtdm_toseq_t *timeout_seq)
 {
        struct xnthread *thread;
+       int err = 0, ret;
        spl_t s;
-       int err = 0;
 
        if (!XENO_ASSERT(COBALT, !xnsched_unblockable_p()))
                return -EPERM;
@@ -1024,18 +1022,18 @@ int rtdm_sem_timeddown(rtdm_sem_t *sem, nanosecs_rel_t 
timeout,
        else {
                thread = xnthread_current();
 
-               if (timeout_seq && (timeout > 0)) {
+               if (timeout_seq && timeout > 0)
                        /* timeout sequence */
-                       xnsynch_sleep_on(&sem->synch_base, *timeout_seq,
-                                        XN_ABSOLUTE);
-               } else
+                       ret = xnsynch_sleep_on(&sem->synch_base, *timeout_seq,
+                                              XN_ABSOLUTE);
+               else
                        /* infinite or relative timeout */
-                       xnsynch_sleep_on(&sem->synch_base, timeout, 
XN_RELATIVE);
+                       ret = xnsynch_sleep_on(&sem->synch_base, timeout, 
XN_RELATIVE);
 
-               if (xnthread_test_info(thread, XNTIMEO | XNRMID | XNBREAK)) {
-                       if (xnthread_test_info(thread, XNTIMEO))
+               if (ret) {
+                       if (ret & XNTIMEO)
                                err = -ETIMEDOUT;
-                       else if (xnthread_test_info(thread, XNRMID))
+                       else if (ret & XNRMID)
                                err = -EIDRM;
                        else /* XNBREAK */
                                err = -EINTR;
diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index 8787206..7773a08 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -189,7 +189,7 @@ int xnsynch_sleep_on(struct xnsynch *synch, xnticks_t 
timeout,
 
        xnlock_put_irqrestore(&nklock, s);
 
-       return (int)xnthread_test_info(thread, XNRMID|XNTIMEO|XNBREAK);
+       return xnthread_test_info(thread, XNRMID|XNTIMEO|XNBREAK);
 }
 EXPORT_SYMBOL_GPL(xnsynch_sleep_on);
 


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

Reply via email to