Date: Tue, 22 Apr 1997 13:55:07 +0930 (CST) From: Michael Smith <msmith@atrad.adelaide.edu.au> To: luigi@labinfo.iet.unipi.it (Luigi Rizzo) Cc: msmith@atrad.adelaide.edu.au, hackers@freebsd.org Subject: Re: concurrent calls to device drivers Message-ID: <199704220425.NAA12940@genesis.atrad.adelaide.edu.au> In-Reply-To: <199704210727.JAA15119@labinfo.iet.unipi.it> from Luigi Rizzo at "Apr 21, 97 09:27:37 am"
next in thread | previous in thread | raw e-mail | index | archive | help
Luigi Rizzo stands accused of saying:
> [previous thread about possible bug in /dev/spkr ]
>
> > The driver claims to only permit a single opener, which as Bruce has
> > pointed out before is pointless as fd's are duplicated across forks.
>
> which reminds me that many device drivers in /sys/i386/isa (some
> of which were contributed by me... :( ) are "broken" in the same
> way: they keep a flag to remember that the device is open, but do
> not prevent concurrent calls, assuming the single open as a guarantee
> that there are no concurrent calls. The assumption is false not
> only because of forks, but presumably also when threads are used.
>
> At a quick glance the involved devices in /sys/i386/isa are
>
> pcaudio, bqu (transputer), asc, gsc, gpib, joy, qcam
>
> Perhaps devices should keep a "busy" flag to prevent concurrent
> calls, rather than limiting to insure a single open.
That's ususally the best way to go; something like :
sc_busy;
...
fooread(...)
{
...
s = splfoo();
while(sc->sc_busy) {
rv = tsleep((caddr_t)&sc->sc_busy, PCATCH, "fooread", 0);
if (rv == -1) {
splx(s);
return(EINTR);
}
}
sc->sc_busy = 1;
splx(s);
...
innards of fooread
...
s = splfoo();
sc->sc_busy = 0;
wakeup((caddr_t)&sc->sc_busy;
splx(s);
return(...)
}
will ensure that only one reader (for example) will be in the
'innards' section at any one time. The splfoo/splx may not be required
at the exit end of things, but if kernel preemption ever happens, it'll
be important 8)
--
]] Mike Smith, Software Engineer msmith@gsoft.com.au [[
]] Genesis Software genesis@gsoft.com.au [[
]] High-speed data acquisition and (GSM mobile) 0411-222-496 [[
]] realtime instrument control. (ph) +61-8-8267-3493 [[
]] Unix hardware collector. "Where are your PEZ?" The Tick [[
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199704220425.NAA12940>
