132380Sminshall /* 233685Sbostic * Copyright (c) 1988 Regents of the University of California. 333685Sbostic * All rights reserved. 433685Sbostic * 542770Sbostic * %sccs.include.redist.c% 633685Sbostic * 7*44360Sborman * @(#)ring.h 1.10 (Berkeley) 06/28/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 42*44360Sborman ring_supply_data(Ring *ring, char *buffer, int count); 43*44360Sborman #ifdef notdef 44*44360Sborman extern void 4532528Sminshall ring_consume_data(Ring *ring, char *buffer, int count); 46*44360Sborman #endif 4732380Sminshall 4832380Sminshall /* Buffer state transition routines */ 4932380Sminshall extern void 5032528Sminshall ring_supplied(Ring *ring, int count), 5132528Sminshall ring_consumed(Ring *ring, int count); 5232380Sminshall 5332380Sminshall /* Buffer state query routines */ 5432380Sminshall extern int 5532380Sminshall ring_empty_count(Ring *ring), 5632380Sminshall ring_empty_consecutive(Ring *ring), 5732528Sminshall ring_full_count(Ring *ring), 5832528Sminshall ring_full_consecutive(Ring *ring); 5932380Sminshall 6034848Sminshall #else /* LINT_ARGS */ 6134848Sminshall extern int 6234848Sminshall ring_init(); 6334848Sminshall 6434848Sminshall extern void 65*44360Sborman ring_supply_data(); 66*44360Sborman #ifdef notdef 67*44360Sborman extern void 6834848Sminshall ring_consume_data(); 69*44360Sborman #endif 7034848Sminshall 7134848Sminshall extern void 7234848Sminshall ring_supplied(), 7334848Sminshall ring_consumed(); 7434848Sminshall 7534848Sminshall extern void 7634848Sminshall ring_clear_mark(), 7734848Sminshall ring_mark(); 7834848Sminshall 7934848Sminshall extern int 8034848Sminshall ring_empty_count(), 8134848Sminshall ring_empty_consecutive(), 8234848Sminshall ring_full_count(), 8334848Sminshall ring_full_consecutive(); 8432380Sminshall #endif /* defined(LINT_ARGS) */ 85