On 18-May-2002 Terry Lambert wrote:
> John Baldwin wrote:
>> On 18-May-2002 Terry Lambert wrote:
>> > John Baldwin wrote:
>> >> > God, it's annoying that a statically declared mutex is not
>> >> > defacto initialized.
>> >>
>> >> Is it in solaris?
>> >
>> > It isn't in FreeBSD because of the need to link mutex'es into
>> > the "witness protection program".  8-).
>> 
>> Actually, there is more to it than that.  Or at least, there will be
>> when turnstiles are added (turnstiles require some function callouts
>> to work properly).
> 
> It's the function callouts that are the problem.  8-(.

Unfortunately there aren't easy solutions to this.  Even solaris 7
uses callouts.  We would use fewer of them at least.

>> > MUTEX_DECLARE(mutex_name).
>> 
>> Umm, yes, like MTX_SYSINIT(). :)
> 
> No.  An MTX_SYSINIT() that wrapped a declaration and a SYSINIT()
> would als imply the definition of an static function to do the
> initialization, that then got called by the SYSINIT() itself.

This is a false implication.

> This is actually what I was saying was bad: a static function
> per mutex declaration.

Umm, no, there is _one_ global function that we call.  Why not check
the actual code?

> So, among other things, you want to use the same initializer function
> instance for all statically declared mutexes.

Um, we already do this.

> So you have to use something other than a SYSINIT() for the declarations,
> but you could use *one SYSINIT()* to do the pre-use initialization of
> *all* declarations.

Why don't you read the code?

Here, I'll quote it for you:

struct mtx_args {
        struct mtx      *ma_mtx;
        const char      *ma_desc;
        int              ma_opts;
};

#define MTX_SYSINIT(name, mtx, desc, opts)                              \
        static struct mtx_args name##_args = {                          \
                mtx,                                                    \
                desc,                                                   \
                opts                                                    \
        };                                                              \
        SYSINIT(name##_mtx_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE,       \
            mtx_sysinit, &name##_args)

Note no static function, instead we use the global function mtx_sysinit()
in kern_mutex.c:

/*
 * General init routine used by the MTX_SYSINIT() macro.
 */
void
mtx_sysinit(void *arg)
{
        struct mtx_args *margs = arg;

        mtx_init(margs->ma_mtx, margs->ma_desc, NULL, margs->ma_opts);
}

-- 

John Baldwin <[EMAIL PROTECTED]>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve!"  -  http://www.FreeBSD.org/

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to