From 74a4d8c26dd3c1e9febcb717cfd6cb6512991a7a Mon Sep 17 00:00:00 2001 From: "Charles.Forsyth" Date: Fri, 22 Dec 2006 21:39:35 +0000 Subject: 20060303 --- os/boot/pc/queue.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 os/boot/pc/queue.c (limited to 'os/boot/pc/queue.c') diff --git a/os/boot/pc/queue.c b/os/boot/pc/queue.c new file mode 100644 index 00000000..d2a529cd --- /dev/null +++ b/os/boot/pc/queue.c @@ -0,0 +1,44 @@ +#include "u.h" +#include "lib.h" +#include "mem.h" +#include "dat.h" +#include "fns.h" +#include "io.h" + +int +qgetc(IOQ *q) +{ + int c; + + if(q->in == q->out) + return -1; + c = *q->out; + if(q->out == q->buf+sizeof(q->buf)-1) + q->out = q->buf; + else + q->out++; + return c; +} + +static int +qputc(IOQ *q, int c) +{ + uchar *nextin; + if(q->in >= &q->buf[sizeof(q->buf)-1]) + nextin = q->buf; + else + nextin = q->in+1; + if(nextin == q->out) + return -1; + *q->in = c; + q->in = nextin; + return 0; +} + +void +qinit(IOQ *q) +{ + q->in = q->out = q->buf; + q->getc = qgetc; + q->putc = qputc; +} -- cgit v1.2.3