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

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Wed Jun 15 22:12:06 2011 +0200

native: fix condvars to avoid using errno as a temporary

---

 ksrc/skins/native/syscall.c |   31 ++++++++++++++++++---------
 src/skins/native/cond.c     |   48 ++++++++++--------------------------------
 2 files changed, 33 insertions(+), 46 deletions(-)

diff --git a/ksrc/skins/native/syscall.c b/ksrc/skins/native/syscall.c
index 556c567..4b29e2e 100644
--- a/ksrc/skins/native/syscall.c
+++ b/ksrc/skins/native/syscall.c
@@ -1822,13 +1822,19 @@ static int __rt_cond_delete(struct pt_regs *regs)
  *                            RTIME *timeoutp)
  */
 
+struct us_cond_data {
+       unsigned lockcnt;
+       int err;
+};
+
 static int __rt_cond_wait_prologue(struct pt_regs *regs)
 {
        RT_COND_PLACEHOLDER cph, mph;
        xntmode_t timeout_mode;
+       struct us_cond_data d;
        int err, perr = 0;
-       unsigned lockcnt;
        RT_MUTEX *mutex;
+       unsigned dummy;
        RT_COND *cond;
        RTIME timeout;
 
@@ -1856,26 +1862,31 @@ static int __rt_cond_wait_prologue(struct pt_regs *regs)
                                     sizeof(timeout)))
                return -EFAULT;
 
-       err = rt_cond_wait_prologue(cond, mutex, &lockcnt, timeout_mode, 
timeout);
+#ifdef CONFIG_XENO_FASTSYNCH
+       if (__xn_safe_copy_from_user(&d, (void __user *)__xn_reg_arg3(regs),
+                                    sizeof(d)))
+               return -EFAULT;
 
+       err = rt_cond_wait_prologue(cond, mutex, &dummy, timeout_mode, timeout);
+#else /* !CONFIG_XENO_FASTSYNCH */
+       err = rt_cond_wait_prologue(cond, mutex, &d.lockcnt, timeout_mode, 
timeout);
+#endif /* !CONFIG_XENO_FASTSYNCH */
        switch(err) {
        case 0:
        case -ETIMEDOUT:
        case -EIDRM:
-               perr = rt_task_errno = err;
-               err = rt_cond_wait_epilogue(mutex, lockcnt);
+               perr = d.err = err;
+               err = rt_cond_wait_epilogue(mutex, d.lockcnt);
                break;
 
        case -EINTR:
                perr = err;
-               rt_task_errno = 0; /* epilogue should return 0. */
+               d.err = 0; /* epilogue should return 0. */
                break;
        }
 
-       if (err == -EINTR
-           && __xn_reg_arg3(regs)
-           && __xn_safe_copy_to_user((void __user *)__xn_reg_arg3(regs),
-                                     &lockcnt, sizeof(lockcnt)))
+       if (__xn_safe_copy_to_user((void __user *)__xn_reg_arg3(regs),
+                                  &d, sizeof(d)))
                return -EFAULT;
 
        return err == 0 ? perr : err;
@@ -1905,7 +1916,7 @@ static int __rt_cond_wait_epilogue(struct pt_regs *regs)
 
        err = rt_cond_wait_epilogue(mutex, lockcnt);
 
-       return err == 0 ? rt_task_errno : err;
+       return err;
 }
 
 /*
diff --git a/src/skins/native/cond.c b/src/skins/native/cond.c
index cf7a639..a7d20a8 100644
--- a/src/skins/native/cond.c
+++ b/src/skins/native/cond.c
@@ -44,6 +44,7 @@ int rt_cond_delete(RT_COND *cond)
 struct rt_cond_cleanup_t {
        RT_MUTEX *mutex;
        unsigned saved_lockcnt;
+       int err;
 };
 
 static void __rt_cond_cleanup(void *data)
@@ -75,26 +76,11 @@ int rt_cond_wait(RT_COND *cond, RT_MUTEX *mutex, RTIME 
timeout)
 
 #ifdef CONFIG_XENO_FASTSYNCH
        c.saved_lockcnt = mutex->lockcnt;
+#endif /* CONFIG_XENO_FASTSYNCH */
 
        err = XENOMAI_SKINCALL5(__native_muxid,
                                __native_cond_wait_prologue, cond, mutex,
-                               NULL, XN_RELATIVE, &timeout);
-
-       while (err == -EINTR)
-               err = XENOMAI_SKINCALL2(__native_muxid,
-                                       __native_cond_wait_epilogue, mutex,
-                                       c.saved_lockcnt);
-
-       pthread_setcanceltype(oldtype, NULL);
-
-       pthread_cleanup_pop(0);
-
-       mutex->lockcnt = c.saved_lockcnt;
-
-#else /* !CONFIG_XENO_FASTSYNCH */
-       err = XENOMAI_SKINCALL5(__native_muxid,
-                                __native_cond_wait_prologue, cond, mutex,
-                                &c.saved_lockcnt, XN_RELATIVE, &timeout);
+                               &c.saved_lockcnt, XN_RELATIVE, &timeout);
 
        pthread_setcanceltype(oldtype, NULL);
 
@@ -105,11 +91,13 @@ int rt_cond_wait(RT_COND *cond, RT_MUTEX *mutex, RTIME 
timeout)
                                        __native_cond_wait_epilogue, mutex,
                                        c.saved_lockcnt);
 
-#endif /* !CONFIG_XENO_FASTSYNCH */
+#ifdef CONFIG_XENO_FASTSYNCH
+       mutex->lockcnt = c.saved_lockcnt;
+#endif /* CONFIG_XENO_FASTSYNCH */
 
        pthread_testcancel();
 
-       return err;
+       return err ?: c.err;
 }
 
 int rt_cond_wait_until(RT_COND *cond, RT_MUTEX *mutex, RTIME timeout)
@@ -125,10 +113,11 @@ int rt_cond_wait_until(RT_COND *cond, RT_MUTEX *mutex, 
RTIME timeout)
 
 #ifdef CONFIG_XENO_FASTSYNCH
        c.saved_lockcnt = mutex->lockcnt;
+#endif /* CONFIG_XENO_FASTSYNCH */
 
        err = XENOMAI_SKINCALL5(__native_muxid,
                                __native_cond_wait_prologue, cond, mutex,
-                               NULL, XN_REALTIME, &timeout);
+                               &c.saved_lockcnt, XN_REALTIME, &timeout);
 
        pthread_setcanceltype(oldtype, NULL);
 
@@ -139,26 +128,13 @@ int rt_cond_wait_until(RT_COND *cond, RT_MUTEX *mutex, 
RTIME timeout)
                                        __native_cond_wait_epilogue, mutex,
                                        c.saved_lockcnt);
 
+#ifdef CONFIG_XENO_FASTSYNCH
        mutex->lockcnt = c.saved_lockcnt;
-
-#else /* !CONFIG_XENO_FASTSYNCH */
-       err = XENOMAI_SKINCALL5(__native_muxid,
-                               __native_cond_wait_prologue, cond, mutex,
-                               &c.saved_lockcnt, XN_REALTIME, &timeout);
-
-       pthread_setcanceltype(oldtype, NULL);
-
-       pthread_cleanup_pop(0);
-
-       while (err == -EINTR)
-               err = XENOMAI_SKINCALL2(__native_muxid,
-                                       __native_cond_wait_epilogue, mutex,
-                                       c.saved_lockcnt);
-#endif /* !CONFIG_XENO_FASTSYNCH */
+#endif /* CONFIG_XENO_FASTSYNCH */
 
        pthread_testcancel();
 
-       return err;
+       return err ?: c.err;
 }
 
 int rt_cond_signal(RT_COND *cond)


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

Reply via email to