Module: xenomai-gch
Branch: for-head
Commit: 8b65bb9a6f90f7e6d2cbfc97f7b01e24608c24bf
URL:    
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=8b65bb9a6f90f7e6d2cbfc97f7b01e24608c24bf

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Wed Nov 25 07:16:51 2009 +0100

posix: fix pthread_cond_wait restarting

---

 ksrc/skins/posix/syscall.c |   28 ++++++++++------------------
 src/skins/posix/cond.c     |   44 ++++++++++++--------------------------------
 2 files changed, 22 insertions(+), 50 deletions(-)

diff --git a/ksrc/skins/posix/syscall.c b/ksrc/skins/posix/syscall.c
index c08db8b..959b61c 100644
--- a/ksrc/skins/posix/syscall.c
+++ b/ksrc/skins/posix/syscall.c
@@ -1560,24 +1560,15 @@ static int __pthread_cond_wait_prologue(struct pt_regs 
*regs)
                                                    &mx.shadow_mutex,
                                                    &count, timed, XN_INFINITE);
 
-       if (err == EINTR) {
-               do {
-                       xnthread_clear_info(cur, XNKICKED);
-                       err =
-                           pse51_cond_timedwait_epilogue(cur, &cnd.shadow_cond,
-                                                         &mx.shadow_mutex,
-                                                         count);
-               }
-               while (err == -EINTR);
-               xnthread_set_info(cur, XNKICKED);
-               err = EINTR;
-       }
+       if (err == 0 || err == ETIMEDOUT)
+               err = -pse51_cond_timedwait_epilogue(cur, &cnd.shadow_cond,
+                                                   &mx.shadow_mutex, count);
 
-       if (!err || err == EINTR || err == ETIMEDOUT)
-               if (__xn_safe_copy_to_user((void __user *)__xn_reg_arg3(regs),
-                                          &count, sizeof(count)))
+       if (err == EINTR
+           && __xn_safe_copy_to_user((void __user *)__xn_reg_arg3(regs),
+                                     &count, sizeof(count)))
                        err = EFAULT;
-
+       
        return -err;
 }
 
@@ -2771,7 +2762,8 @@ static xnsysent_t __systab[] = {
        [__pse51_clock_getres] = {&__clock_getres, __xn_exec_any},
        [__pse51_clock_gettime] = {&__clock_gettime, __xn_exec_any},
        [__pse51_clock_settime] = {&__clock_settime, __xn_exec_any},
-       [__pse51_clock_nanosleep] = {&__clock_nanosleep, __xn_exec_primary},
+       [__pse51_clock_nanosleep] = {&__clock_nanosleep, 
+                                    __xn_exec_primary | __xn_exec_norestart},
        [__pse51_mutex_init] = {&__pthread_mutex_init, __xn_exec_any},
        [__pse51_mutex_destroy] = {&__pthread_mutex_destroy, __xn_exec_any},
        [__pse51_mutex_lock] = {&__pthread_mutex_lock, __xn_exec_primary},
@@ -2786,7 +2778,7 @@ static xnsysent_t __systab[] = {
        [__pse51_cond_init] = {&__pthread_cond_init, __xn_exec_any},
        [__pse51_cond_destroy] = {&__pthread_cond_destroy, __xn_exec_any},
        [__pse51_cond_wait_prologue] =
-           {&__pthread_cond_wait_prologue, __xn_exec_primary},
+           {&__pthread_cond_wait_prologue, __xn_exec_primary | 
__xn_exec_norestart},
        [__pse51_cond_wait_epilogue] =
            {&__pthread_cond_wait_epilogue, __xn_exec_primary},
        [__pse51_cond_signal] = {&__pthread_cond_signal, __xn_exec_any},
diff --git a/src/skins/posix/cond.c b/src/skins/posix/cond.c
index 171789d..0582367 100644
--- a/src/skins/posix/cond.c
+++ b/src/skins/posix/cond.c
@@ -89,12 +89,15 @@ struct pse51_cond_cleanup_t {
 static void __pthread_cond_cleanup(void *data)
 {
        struct pse51_cond_cleanup_t *c = (struct pse51_cond_cleanup_t *) data;
+       int err;
 
-       XENOMAI_SKINCALL3(__pse51_muxid,
-                         __pse51_cond_wait_epilogue,
-                         &c->cond->shadow_cond,
-                         &c->mutex->shadow_mutex,
-                         c->count);
+       do {
+               err = -XENOMAI_SKINCALL3(__pse51_muxid,
+                                       __pse51_cond_wait_epilogue,
+                                       &c->cond->shadow_cond,
+                                       &c->mutex->shadow_mutex,
+                                       c->count);
+       } while (err == EINTR);
 }
 
 int __wrap_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
@@ -116,34 +119,23 @@ int __wrap_pthread_cond_wait(pthread_cond_t *cond, 
pthread_mutex_t *mutex)
                                 __pse51_cond_wait_prologue,
                                 &c.cond->shadow_cond,
                                 &c.mutex->shadow_mutex, &c.count, 0, NULL);
+
        pthread_setcanceltype(oldtype, NULL);
 
        pthread_cleanup_pop(0);
 
-       if (err) {
-               if (err == EINTR)
-                       err = 0;
-
-               cb_read_unlock(&c.mutex->shadow_mutex.lock, s);
-
-               pthread_testcancel();
-
-               return err;
-       }
-
-       do {
+       while (err == EINTR)
                err = -XENOMAI_SKINCALL3(__pse51_muxid,
                                         __pse51_cond_wait_epilogue,
                                         &c.cond->shadow_cond,
                                         &c.mutex->shadow_mutex,
                                         c.count);
-       } while (err == EINTR);
 
        cb_read_unlock(&c.mutex->shadow_mutex.lock, s);
 
        pthread_testcancel();
 
-       return 0;
+       return err;
 }
 
 int __wrap_pthread_cond_timedwait(pthread_cond_t * cond,
@@ -171,24 +163,12 @@ int __wrap_pthread_cond_timedwait(pthread_cond_t * cond,
 
        pthread_cleanup_pop(0);
 
-       if (err && err != ETIMEDOUT) {
-               if (err == EINTR)
-                       err = 0;
-               
-               cb_read_unlock(&c.mutex->shadow_mutex.lock, s);         
-
-               pthread_testcancel();
-
-               return err;
-       }
-
-       do {
+       while (err == EINTR)
                err = -XENOMAI_SKINCALL3(__pse51_muxid,
                                         __pse51_cond_wait_epilogue,
                                         &c.cond->shadow_cond,
                                         &c.mutex->shadow_mutex,
                                         c.count);
-       } while (err == EINTR);
 
        cb_read_unlock(&c.mutex->shadow_mutex.lock, s);
 


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

Reply via email to