132380Sminshall /* 233685Sbostic * Copyright (c) 1988 Regents of the University of California. 333685Sbostic * All rights reserved. 433685Sbostic * 5*42770Sbostic * %sccs.include.redist.c% 633685Sbostic * 7*42770Sbostic * @(#)ring.h 1.9 (Berkeley) 06/01/90 833685Sbostic */ 933685Sbostic 1033685Sbostic /* 1132528Sminshall * This defines a structure for a ring buffer. 1232380Sminshall * 1332528Sminshall * The circular buffer has two parts: 1432380Sminshall *((( 1532528Sminshall * full: [consume, supply) 1632528Sminshall * empty: [supply, consume) 1732380Sminshall *]]] 1832380Sminshall * 1932380Sminshall */ 2032380Sminshall typedef struct { 2132528Sminshall char *consume, /* where data comes out of */ 2232528Sminshall *supply, /* where data comes in to */ 2332380Sminshall *bottom, /* lowest address in buffer */ 2433294Sminshall *top, /* highest address+1 in buffer */ 2533294Sminshall *mark; /* marker (user defined) */ 2632380Sminshall int size; /* size in bytes of buffer */ 2732528Sminshall u_long consumetime, /* help us keep straight full, empty, etc. */ 2832528Sminshall supplytime; 2932380Sminshall } Ring; 3032380Sminshall 3132380Sminshall /* Here are some functions and macros to deal with the ring buffer */ 3232380Sminshall 3332380Sminshall 3432380Sminshall #if defined(LINT_ARGS) 3532380Sminshall 3632381Sminshall /* Initialization routine */ 3732381Sminshall extern int 3832381Sminshall ring_init(Ring *ring, char *buffer, int count); 3932381Sminshall 4032380Sminshall /* Data movement routines */ 4132380Sminshall extern void 4232528Sminshall ring_supply_data(Ring *ring, char *buffer, int count), 4332528Sminshall ring_consume_data(Ring *ring, char *buffer, int count); 4432380Sminshall 4532380Sminshall /* Buffer state transition routines */ 4632380Sminshall extern void 4732528Sminshall ring_supplied(Ring *ring, int count), 4832528Sminshall ring_consumed(Ring *ring, int count); 4932380Sminshall 5032380Sminshall /* Buffer state query routines */ 5132380Sminshall extern int 5232380Sminshall ring_empty_count(Ring *ring), 5332380Sminshall ring_empty_consecutive(Ring *ring), 5432528Sminshall ring_full_count(Ring *ring), 5532528Sminshall ring_full_consecutive(Ring *ring); 5632380Sminshall 5734848Sminshall #else /* LINT_ARGS */ 5834848Sminshall extern int 5934848Sminshall ring_init(); 6034848Sminshall 6134848Sminshall extern void 6234848Sminshall ring_supply_data(), 6334848Sminshall ring_consume_data(); 6434848Sminshall 6534848Sminshall extern void 6634848Sminshall ring_supplied(), 6734848Sminshall ring_consumed(); 6834848Sminshall 6934848Sminshall extern void 7034848Sminshall ring_clear_mark(), 7134848Sminshall ring_mark(); 7234848Sminshall 7334848Sminshall extern int 7434848Sminshall ring_empty_count(), 7534848Sminshall ring_empty_consecutive(), 7634848Sminshall ring_full_count(), 7734848Sminshall ring_full_consecutive(); 7832380Sminshall #endif /* defined(LINT_ARGS) */ 79