All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Gerum <rpm@xenomai.org>
To: Anders Blomdell <anders.blomdell@domain.hid>
Cc: xenomai-help <xenomai@xenomai.org>, xenomai-core <xenomai@xenomai.org>
Subject: Re: [Xenomai-core] [Xenomai-help] What have I misunderstood about	condition	variables
Date: Wed, 12 Mar 2008 15:14:00 +0100	[thread overview]
Message-ID: <47D7E528.9060704@domain.hid> (raw)
In-Reply-To: <47D6E7D8.90908@domain.hid>

Anders Blomdell wrote:
> OK, found the bug (not mine!).

No, it's mine. Actually, you fixed two of them, since nested locks would not be
released properly when entering cond_wait. Will merge, thanks.

 I suggest something like this:
> 
> --- ksrc/skins/native/cond.c.orig       2008-03-11 20:42:52.000000000 +0100
> +++ ksrc/skins/native/cond.c    2008-03-11 21:00:10.000000000 +0100
> @@ -438,13 +438,20 @@
> 
>  int rt_cond_wait(RT_COND *cond, RT_MUTEX *mutex, RTIME timeout)
>  {
> -       int err, kicked = 0;
> +       /* We can't use rt_mutex_release since that might reschedule
> +          before we do our xnsynch_sleep_on, hence most of of the code
> +          is duplicated here */
> +       int err = 0, kicked = 0;
>         xnthread_t *thread;
>         spl_t s;
> +       int lockcnt;
> 
>         if (timeout == TM_NONBLOCK)
>                 return -EWOULDBLOCK;
> 
> +       if (xnpod_unblockable_p())
> +               return -EPERM;
> +
>         xnlock_get_irqsave(&nklock, s);
> 
>         cond = xeno_h2obj_validate(cond, XENO_COND_MAGIC, RT_COND);
> @@ -454,10 +461,26 @@
>                 goto unlock_and_exit;
>         }
> 
> -       err = rt_mutex_release(mutex);
> +       mutex = xeno_h2obj_validate(mutex, XENO_MUTEX_MAGIC, RT_MUTEX);
> 
> -       if (err)
> +       if (!mutex) {
> +               err = xeno_handle_error(mutex, XENO_MUTEX_MAGIC, RT_MUTEX);
> +               goto unlock_and_exit;
> +       }
> +
> +       if (xnpod_current_thread() != xnsynch_owner(&mutex->synch_base)) {
> +               err = -EPERM;
>                 goto unlock_and_exit;
> +       }
> +
> +       lockcnt = mutex->lockcnt; /* Leave even if mutex is nested */
> +
> +       mutex->lockcnt = 0;
> +
> +       if (xnsynch_wakeup_one_sleeper(&mutex->synch_base)) {
> +               mutex->lockcnt = 1;
> +               /* Scheduling deferred */
> +       }
> 
>         thread = xnpod_current_thread();
> 
> @@ -474,6 +497,8 @@
> 
>         rt_mutex_acquire(mutex, TM_INFINITE);
> 
> +       mutex->lockcnt = lockcnt; /* Adjust lockcnt */
> +
>         if (kicked)
>                 xnthread_set_info(thread, XNKICKED);
> 
> 
> 
> 


-- 
Philippe.


  reply	other threads:[~2008-03-12 14:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-11 18:19 [Xenomai-help] What have I misunderstood about condition variables Anders Blomdell
2008-03-11 18:27 ` Gilles Chanteperdrix
2008-03-11 19:27   ` Anders Blomdell
2008-03-11 20:13     ` [Xenomai-core] " Anders Blomdell
2008-03-12 14:14       ` Philippe Gerum [this message]
2008-03-11 23:00     ` Gilles Chanteperdrix
2008-03-12 12:00       ` Anders Blomdell
2008-03-12 13:11         ` Gilles Chanteperdrix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47D7E528.9060704@domain.hid \
    --to=rpm@xenomai.org \
    --cc=anders.blomdell@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.