Module: xenomai-jki
Branch: for-upstream
Commit: 9ef3af309a733f59512d745de32de6f3fc2d46ea
URL:    
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=9ef3af309a733f59512d745de32de6f3fc2d46ea

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Tue Mar  2 14:29:02 2010 +0100

POSIX: Fix in-kernel pthread_cond_[timed]wait

Make sure that we always try to reacquire the mutex, even if the
prologue failed. And return the epilogue error in case the prologue was
successful.

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

---

 ksrc/skins/posix/cond.c |   30 +++++++++++++++++-------------
 1 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/ksrc/skins/posix/cond.c b/ksrc/skins/posix/cond.c
index 1b74b80..f222173 100644
--- a/ksrc/skins/posix/cond.c
+++ b/ksrc/skins/posix/cond.c
@@ -343,7 +343,7 @@ int pse51_cond_timedwait_epilogue(xnthread_t *cur,
 
        /* Unbind mutex and cond, if no other thread is waiting, if the job was
           not already done. */
-       if (!xnsynch_nsleepers(&cond->synchbase)
+       if (cond && !xnsynch_nsleepers(&cond->synchbase)
            && cond->mutex == mutex->mutex)
                cond->mutex = NULL;
 
@@ -412,7 +412,7 @@ int pthread_cond_wait(pthread_cond_t * cnd, pthread_mutex_t 
* mx)
            &((union __xeno_mutex *)mx)->shadow_mutex;
        xnthread_t *cur = xnpod_current_thread();
        unsigned count;
-       int err;
+       int err, epilogue_err;
 
 #ifdef CONFIG_XENO_FASTSYNCH
        if (unlikely(cb_try_read_lock(&mutex->lock, s)))
@@ -421,17 +421,19 @@ int pthread_cond_wait(pthread_cond_t * cnd, 
pthread_mutex_t * mx)
 
        err = pse51_cond_timedwait_prologue(cur, cond, mutex,
                                            &count, 0, XN_INFINITE);
+       if (err == -EIDRM)
+               cond = NULL;
 
-       if (!err || err == EINTR)
-               while (EINTR == pse51_cond_timedwait_epilogue(cur, cond,
-                                                             mutex, count))
-                       ;
+       do {
+               epilogue_err = pse51_cond_timedwait_epilogue(cur, cond,
+                                                            mutex, count);
+       } while (epilogue_err == -EINTR);
 
 #ifdef CONFIG_XENO_FASTSYNCH
        cb_read_unlock(&mutex->lock, s);
 #endif /* CONFIG_XENO_FASTSYNCH */
 
-       return err != EINTR ? err : 0;
+       return err != EINTR ? err : epilogue_err;
 }
 
 /**
@@ -480,7 +482,7 @@ int pthread_cond_timedwait(pthread_cond_t * cnd,
            &((union __xeno_mutex *)mx)->shadow_mutex;
        xnthread_t *cur = xnpod_current_thread();
        unsigned count;
-       int err;
+       int err, epilogue_err;
 
 #ifdef CONFIG_XENO_FASTSYNCH
        if (unlikely(cb_try_read_lock(&mutex->lock, s)))
@@ -489,17 +491,19 @@ int pthread_cond_timedwait(pthread_cond_t * cnd,
 
        err = pse51_cond_timedwait_prologue(cur, cond, mutex, &count, 1,
                                            ts2ticks_ceil(abstime) + 1);
+       if (err == -EIDRM)
+               cond = NULL;
 
-       if (!err || err == EINTR || err == ETIMEDOUT)
-               while (EINTR == pse51_cond_timedwait_epilogue(cur, cond,
-                                                             mutex, count))
-                       ;
+       do {
+               epilogue_err = pse51_cond_timedwait_epilogue(cur, cond,
+                                                            mutex, count);
+       } while (epilogue_err == -EINTR);
 
 #ifdef CONFIG_XENO_FASTSYNCH
        cb_read_unlock(&mutex->lock, s);
 #endif /* CONFIG_XENO_FASTSYNCH */
 
-       return err != EINTR ? err : 0;
+       return err != EINTR ? err : epilogue_err;
 }
 
 /**


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

Reply via email to