Module: xenomai-jki Branch: for-upstream Commit: 135ed5086d3f2c38f4a697d0d2a8e4e66411bca4 URL: http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=135ed5086d3f2c38f4a697d0d2a8e4e66411bca4
Author: Jan Kiszka <jan.kis...@siemens.com> Date: Tue Mar 2 13:17:35 2010 +0100 Native: Ensure to re-acquire the mutex on cond_wait return Always try to reacquire the mutex if the prologue released it. The only exception is user space return on interruption. Signed-off-by: Jan Kiszka <jan.kis...@siemens.com> --- ksrc/skins/native/cond.c | 17 +++++++++++------ ksrc/skins/native/syscall.c | 6 ++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ksrc/skins/native/cond.c b/ksrc/skins/native/cond.c index d6c8546..6076472 100644 --- a/ksrc/skins/native/cond.c +++ b/ksrc/skins/native/cond.c @@ -380,6 +380,8 @@ int rt_cond_wait_prologue(RT_COND *cond, RT_MUTEX *mutex, unsigned *plockcnt, spl_t s; int err; + *plockcnt = 0; + if (timeout == TM_NONBLOCK) return -EWOULDBLOCK; @@ -467,15 +469,18 @@ static int rt_cond_wait_inner(RT_COND *cond, RT_MUTEX *mutex, xntmode_t timeout_mode, RTIME timeout) { unsigned lockcnt; - int err, epilogue_err = 0; + int err, epilogue_err; - err = rt_cond_wait_prologue(cond, mutex, &lockcnt, + err = rt_cond_wait_prologue(cond, mutex, &lockcnt, timeout_mode, timeout); - if(!err || err == -ETIMEDOUT || err == -EINTR) - do { - epilogue_err = rt_cond_wait_epilogue(mutex, lockcnt); - } while (epilogue_err == -EINTR); + if (!lockcnt) + return err; + + /* Reacquire the mutex if it was unlocked in the prologue. */ + do { + epilogue_err = rt_cond_wait_epilogue(mutex, lockcnt); + } while (epilogue_err == -EINTR); return err ? err : epilogue_err; } diff --git a/ksrc/skins/native/syscall.c b/ksrc/skins/native/syscall.c index 40e5cfd..462ee7e 100644 --- a/ksrc/skins/native/syscall.c +++ b/ksrc/skins/native/syscall.c @@ -1869,9 +1869,11 @@ static int __rt_cond_wait_prologue(struct pt_regs *regs) err = rt_cond_wait_prologue(cond, mutex, &lockcnt, timeout_mode, timeout); - if (err == 0 || err == -ETIMEDOUT) + /* Reacquire the mutex if it was unlocked in the prologue and we were + not interrupted. */ + if (lockcnt && err != -EINTR) err = rt_cond_wait_epilogue(mutex, lockcnt); - + if (err == -EINTR && __xn_reg_arg3(regs) && __xn_safe_copy_to_user((void __user *)__xn_reg_arg3(regs), &lockcnt, sizeof(lockcnt))) _______________________________________________ Xenomai-git mailing list Xenomai-git@gna.org https://mail.gna.org/listinfo/xenomai-git