xref: /csrg-svn/usr.bin/telnet/ring.h (revision 33685)
132380Sminshall /*
2*33685Sbostic  * Copyright (c) 1988 Regents of the University of California.
3*33685Sbostic  * All rights reserved.
4*33685Sbostic  *
5*33685Sbostic  * Redistribution and use in source and binary forms are permitted
6*33685Sbostic  * provided that this notice is preserved and that due credit is given
7*33685Sbostic  * to the University of California at Berkeley. The name of the University
8*33685Sbostic  * may not be used to endorse or promote products derived from this
9*33685Sbostic  * software without specific prior written permission. This software
10*33685Sbostic  * is provided ``as is'' without express or implied warranty.
11*33685Sbostic  *
12*33685Sbostic  *	@(#)ring.h	1.6 (Berkeley) 03/08/88
13*33685Sbostic  */
14*33685Sbostic 
15*33685Sbostic /*
1632528Sminshall  * This defines a structure for a ring buffer.
1732380Sminshall  *
1832528Sminshall  * The circular buffer has two parts:
1932380Sminshall  *(((
2032528Sminshall  *	full:	[consume, supply)
2132528Sminshall  *	empty:	[supply, consume)
2232380Sminshall  *]]]
2332380Sminshall  *
2432380Sminshall  */
2532380Sminshall typedef struct {
2632528Sminshall     char	*consume,	/* where data comes out of */
2732528Sminshall     		*supply,	/* where data comes in to */
2832380Sminshall 		*bottom,	/* lowest address in buffer */
2933294Sminshall 		*top,		/* highest address+1 in buffer */
3033294Sminshall 		*mark;		/* marker (user defined) */
3132380Sminshall     int		size;		/* size in bytes of buffer */
3232528Sminshall     u_long	consumetime,	/* help us keep straight full, empty, etc. */
3332528Sminshall 		supplytime;
3432380Sminshall } Ring;
3532380Sminshall 
3632380Sminshall /* Here are some functions and macros to deal with the ring buffer */
3732380Sminshall 
3832380Sminshall 
3932380Sminshall #if	defined(LINT_ARGS)
4032380Sminshall 
4132381Sminshall /* Initialization routine */
4232381Sminshall extern int
4332381Sminshall 	ring_init(Ring *ring, char *buffer, int count);
4432381Sminshall 
4532380Sminshall /* Data movement routines */
4632380Sminshall extern void
4732528Sminshall 	ring_supply_data(Ring *ring, char *buffer, int count),
4832528Sminshall 	ring_consume_data(Ring *ring, char *buffer, int count);
4932380Sminshall 
5032380Sminshall /* Buffer state transition routines */
5132380Sminshall extern void
5232528Sminshall 	ring_supplied(Ring *ring, int count),
5332528Sminshall 	ring_consumed(Ring *ring, int count);
5432380Sminshall 
5532380Sminshall /* Buffer state query routines */
5632380Sminshall extern int
5732380Sminshall 	ring_empty_count(Ring *ring),
5832380Sminshall 	ring_empty_consecutive(Ring *ring),
5932528Sminshall 	ring_full_count(Ring *ring),
6032528Sminshall 	ring_full_consecutive(Ring *ring);
6132380Sminshall 
6232380Sminshall #endif	/* defined(LINT_ARGS) */
63