Subject: Re: generic hook infrastructure
To: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
From: Bill Studenmund <wrstuden@netbsd.org>
List: tech-kern
Date: 02/03/2006 09:01:07
--2oS5YaxWCcQjTEyO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Feb 03, 2006 at 12:11:35PM +0900, YAMAMOTO Takashi wrote:
> > > > 1) deregister a hook function after it has run, some of our hooks to
> > > > this to prevent them being run again.
> > >=20
> > > You mean an one-shot modus? I'd say make the hook-removal O(1) with
> > > small O(1) and it can be implemented completely via a wrapper functio=
n.
> >=20
> > Yeah, but I thought the whole point of this was to make a common resour=
ce
> > that captures common behavior.  :-) If we know that we want to
> > remove-after-use all the items on a list, then it seems simpler to have
> > the itterator do it. We then have one hook-remove call rather than one =
per
> > called routine.
>=20
> making a primitive complex for rarely used features is a bad idea, IMO.
> (cf. lockmgr :-)

I think it'd depend. I agree that if we add too much, we bog down the
common case. But I believe there are extra features we can add that won't
add much weight. Well, I think they would add less complexity than
maintaining an extra set of routines would. :-)

I mean I think we're talking about (in VERY butchered pseudo-code):

	TAILQ_FOREACH(h, hook_list_head, hook_next) {
		/* Skip if mask says to skip */
		if (__predict_false((mask_func)
		    && ((mask_func)(mask_func_arg, h->arg) =3D=3D 0))
			continue;
		(h->func)(h->arg);
		if (__predict_false(flags))
			hook_unregister(hook_list_head, h);
	}

So I don't think we're adding much to our primitive. :-)

> unless it's supposed to be used for fast path like pfil as well,
> i don't care, tho.

I'm not sure if this was being thought about for pfil. I think if we=20
consider a fast-path case, it would make sense to have special, leaner=20
list walkers. Like one with masking and unhook and one with neither.

Take care,

Bill

--2oS5YaxWCcQjTEyO
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (NetBSD)

iD8DBQFD44xTWz+3JHUci9cRAmHSAJ9QWqZx/kZKvR/M7vQb0VM8IbZaQgCdHfck
vqXXbGAily/ZLLkrpEs3q9o=
=pu+M
-----END PGP SIGNATURE-----

--2oS5YaxWCcQjTEyO--