Date: Mon, 27 Mar 2000 00:56:20 -0800 (PST) From: Matthew Dillon <dillon@apollo.backplane.com> To: Mike Smith <msmith@FreeBSD.ORG>, Warner Losh <imp@village.org>, Mike Smith <msmith@FreeBSD.ORG>, Daniel Eischen <eischen@vigrid.com>, nms@otdel-1.org, freebsd-current@FreeBSD.ORG Subject: Re: Is there spinlocks/semaphores available for drivers? Message-ID: <200003270856.AAA37203@apollo.backplane.com> References: <200003270720.XAA05430@mass.cdrom.com> <200003270848.AAA37083@apollo.backplane.com>
next in thread | previous in thread | raw e-mail | index | archive | help
SMP FIFO (one writer, one reader):
#define SIZE 256
#define MASK (SIZE-1)
int ri;
int wi;
int fifo[SIZE];
int
fifo_read(void)
{
int r = -1;
if (ri != wi) {
int nri;
r = fifo[ri];
nri = (ri + 1) & MASK;
ri = nri;
}
return(r);
}
int
fifo_write(int v)
{
int nwi = (wi + 1) & MASK;
if (nwi != ri) {
fifo[wi] = v;
wi = nwi;
return(0);
} else {
return(-1);
}
}
int
fifo_ready()
{
return((wi - ri) & MASK)
}
int
fifo_space()
{
return(SIZE - nready() - 1);
}
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200003270856.AAA37203>
