Subject: Re: newlock
To: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
From: Andrew Doran <ad@NetBSD.org>
List: tech-kern
Date: 09/04/2006 02:51:33
On Mon, Sep 04, 2006 at 08:47:38AM +0900, YAMAMOTO Takashi wrote:

> > The assumptions were that we would be dealing with two or more locks, with the
> > same SPL, and that the acquire and release would be done locally. That's not
> > general enough though. So, following your suggestion, something like this:
> > 
> > 	mutex_enter(a);
> > 	.. find b ..
> > 	mutex_enter(b);
> >         mutex_link(b, mutex_exit_linked(a));
> >         .. update b ..
> >         mutex_exit(b);
> > 
> > This is a part of the design I'm not comfortable with, and I think the above
> > is quite ugly. What do people think?
> 
> what's wrong with using plain old splxxx() where out-of-order operation is
> really necessary?  i don't think it's often.

David's suggestion has a couple of advantages that I can see:

- You can raise the SPL via mutex_enter() in find_foo_and_return_locked(),
  and not have to worry about raising or restoring it around the call to the
  function. The mutex contains the saved SPL.

- The SPL is specified in one place.

I guess the the question is whether it's necessary. With the way the mutexes
are imlemented, it's certianly cheap to do.

Andrew