aboutsummaryrefslogtreecommitdiff
path: root/os/boot/pc/queue.c
diff options
context:
space:
mode:
authorbhgv <bhgv.empire@gmail.com>2018-03-01 16:54:45 +0200
committerbhgv <bhgv.empire@gmail.com>2018-03-01 16:54:45 +0200
commitb786f20bbab5a59046aa78a2c6c2a11536497202 (patch)
tree0851ecdec889eb9b7ba3751cc04d4f0b474e4a9e /os/boot/pc/queue.c
inferno-os tree was separated from the inferno-os-android (separated from the Android driver)
Diffstat (limited to 'os/boot/pc/queue.c')
-rw-r--r--os/boot/pc/queue.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/os/boot/pc/queue.c b/os/boot/pc/queue.c
new file mode 100644
index 0000000..d2a529c
--- /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;
+}