Subject: Re: newlock
To: Jason Thorpe <thorpej@shagadelic.org>
From: Hans Petter Selasky <hselasky@c2i.net>
List: tech-kern
Date: 09/04/2006 10:34:46
On Sunday 03 September 2006 23:30, Jason Thorpe wrote:
> On Sep 3, 2006, at 3:13 AM, Hans Petter Selasky wrote:
> > 1) Try to avoid using function/structure names already defined by by
> > the
> > FreeBSD mutex implementation, "man mutex", so that one can put an
> > emulation
> > layer on top that emulates FreeBSD mutexes on NetBSD.
>
> The goal is for the NetBSD API to be like the Solaris API.  That was
> my intent when I originally wrote this code.
>
> > 2) Mutexes must allow recursation.
>
> Absolutely NOT.  Recursive mutexes are just plain evil.  The goal is
> to have a BETTER locking API, not have the same warts as the crappy
> one that we currently have.

If you don't support it I will just make a wrapper for it:

struct mtx {
   kmutex_t  mtx_data;
   u_int16_t mtx_recurse;
   u_int16_t mtx_unused;
};

void
mtx_lock(struct mtx *p_mtx)
{
 if (mutex_held(&(p_mtx->mtx_data)) {
  p_mtx->mtx_recurse ++;
 } else {
  mutex_enter(&(p_mtx->mtx_data));
 }
 return;
}
>
> > 3) Nice if there are some functions that can drop/pickup the
> > recursation
> > count.
>
> Not applicable.
>
> > 4) You need to implement mutex_sleep(), like there is "ltsleep" for
> > simplelocks. Try to avoid the function name "msleep()".
>
> What's wrong with msleep() as a name?

FreeBSD is already using that name. Nice if you can pick another name for it. 
That makes porting code easier.

--HPS