Plan 9 from Bell Labs’s /usr/web/sources/contrib/quanstro/root/sys/src/boot/pc-e820/queue.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"io.h"

int
qgetc(IOQ *q)
{
	int c, x;

	x = splhi();
	if(q->in == q->out){
		splx(x);
		return -1;
	}
	c = *q->out;
	if(q->out == q->buf+sizeof(q->buf)-1)
		q->out = q->buf;
	else
		q->out++;
	splx(x);

	return c;
}

static int
qputc(IOQ *q, int c)
{
	uchar *nextin;
	int x;

	x = splhi();
	if(q->in >= &q->buf[sizeof(q->buf)-1])
		nextin = q->buf;
	else
		nextin = q->in+1;
	if(nextin == q->out){
		splx(x);
		return -1;
	}
	*q->in = c;
	q->in = nextin;
	splx(x);

	return 0;
}

void
qinit(IOQ *q)
{
	q->in = q->out = q->buf;
	q->getc = qgetc;
	q->putc = qputc;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.