New "timeout" api, to replace callout

Poul-Henning Kamp phk at phk.freebsd.dk
Sun Dec 2 07:59:00 PST 2007


In message <20071202.084648.-108809549.imp at bsdimp.com>, "M. Warner Losh" writes
:
>In message: <15391.1196547545 at critter.freebsd.dk>
>            Poul-Henning Kamp <phk at phk.freebsd.dk> writes:

>>>/*
>>> * A duration of time, represented in the optimal way for a given provider
>>> * or family of providers (ie: per cpu).
>>> */
>>>typedef int timeout_time;
>
>What does this mean?  How do I get one of those?  Without a unit
>associated with this number, it becomes hard to do a "tickless"
>implementation.

You get it back from the timeout provider.  The point here is that
most timeout clients use the same time interval again and again,
so precalculating any "magic" values for the specific hardware makes
sense.

In practice your code could look like:


struct foo_softc {

	timeout_time		timeout_duration;
};

...

foo_attach() {


	[...]
	sc->timeout_duration = timeout_conv_time([...], 200, TIMEOUT_MSEC);
}


foo_something() {

	timeout_arm(sc->timeout, sc->timeout_duration, [flags]);
	
}

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.


More information about the freebsd-arch mailing list