xref: /csrg-svn/usr.bin/telnet/ring.h (revision 33294)
132380Sminshall /*
232528Sminshall  * This defines a structure for a ring buffer.
332380Sminshall  *
432528Sminshall  * The circular buffer has two parts:
532380Sminshall  *(((
632528Sminshall  *	full:	[consume, supply)
732528Sminshall  *	empty:	[supply, consume)
832380Sminshall  *]]]
932380Sminshall  *
1032380Sminshall  */
1132380Sminshall typedef struct {
1232528Sminshall     char	*consume,	/* where data comes out of */
1332528Sminshall     		*supply,	/* where data comes in to */
1432380Sminshall 		*bottom,	/* lowest address in buffer */
15*33294Sminshall 		*top,		/* highest address+1 in buffer */
16*33294Sminshall 		*mark;		/* marker (user defined) */
1732380Sminshall     int		size;		/* size in bytes of buffer */
1832528Sminshall     u_long	consumetime,	/* help us keep straight full, empty, etc. */
1932528Sminshall 		supplytime;
2032380Sminshall } Ring;
2132380Sminshall 
2232380Sminshall /* Here are some functions and macros to deal with the ring buffer */
2332380Sminshall 
2432380Sminshall 
2532380Sminshall #if	defined(LINT_ARGS)
2632380Sminshall 
2732381Sminshall /* Initialization routine */
2832381Sminshall extern int
2932381Sminshall 	ring_init(Ring *ring, char *buffer, int count);
3032381Sminshall 
3132380Sminshall /* Data movement routines */
3232380Sminshall extern void
3332528Sminshall 	ring_supply_data(Ring *ring, char *buffer, int count),
3432528Sminshall 	ring_consume_data(Ring *ring, char *buffer, int count);
3532380Sminshall 
3632380Sminshall /* Buffer state transition routines */
3732380Sminshall extern void
3832528Sminshall 	ring_supplied(Ring *ring, int count),
3932528Sminshall 	ring_consumed(Ring *ring, int count);
4032380Sminshall 
4132380Sminshall /* Buffer state query routines */
4232380Sminshall extern int
4332380Sminshall 	ring_empty_count(Ring *ring),
4432380Sminshall 	ring_empty_consecutive(Ring *ring),
4532528Sminshall 	ring_full_count(Ring *ring),
4632528Sminshall 	ring_full_consecutive(Ring *ring);
4732380Sminshall 
4832380Sminshall #endif	/* defined(LINT_ARGS) */
49