From owner-freebsd-current Mon Mar 27 0:56:29 2000 Delivered-To: freebsd-current@freebsd.org Received: from apollo.backplane.com (apollo.backplane.com [216.240.41.2]) by hub.freebsd.org (Postfix) with ESMTP id 7C36937BC43; Mon, 27 Mar 2000 00:56:21 -0800 (PST) (envelope-from dillon@apollo.backplane.com) Received: (from dillon@localhost) by apollo.backplane.com (8.9.3/8.9.1) id AAA37203; Mon, 27 Mar 2000 00:56:20 -0800 (PST) (envelope-from dillon) Date: Mon, 27 Mar 2000 00:56:20 -0800 (PST) From: Matthew Dillon Message-Id: <200003270856.AAA37203@apollo.backplane.com> To: Mike Smith , Warner Losh , Mike Smith , Daniel Eischen , nms@otdel-1.org, freebsd-current@FreeBSD.ORG Subject: Re: Is there spinlocks/semaphores available for drivers? References: <200003270720.XAA05430@mass.cdrom.com> <200003270848.AAA37083@apollo.backplane.com> Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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