132380Sminshall /* 233685Sbostic * Copyright (c) 1988 Regents of the University of California. 333685Sbostic * All rights reserved. 433685Sbostic * 533685Sbostic * Redistribution and use in source and binary forms are permitted 633685Sbostic * provided that this notice is preserved and that due credit is given 733685Sbostic * to the University of California at Berkeley. The name of the University 833685Sbostic * may not be used to endorse or promote products derived from this 933685Sbostic * software without specific prior written permission. This software 1033685Sbostic * is provided ``as is'' without express or implied warranty. 1133685Sbostic * 12*34848Sminshall * @(#)ring.h 1.7 (Berkeley) 06/27/88 1333685Sbostic */ 1433685Sbostic 1533685Sbostic /* 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 62*34848Sminshall #else /* LINT_ARGS */ 63*34848Sminshall extern int 64*34848Sminshall ring_init(); 65*34848Sminshall 66*34848Sminshall extern void 67*34848Sminshall ring_supply_data(), 68*34848Sminshall ring_consume_data(); 69*34848Sminshall 70*34848Sminshall extern void 71*34848Sminshall ring_supplied(), 72*34848Sminshall ring_consumed(); 73*34848Sminshall 74*34848Sminshall extern void 75*34848Sminshall ring_clear_mark(), 76*34848Sminshall ring_mark(); 77*34848Sminshall 78*34848Sminshall extern int 79*34848Sminshall ring_empty_count(), 80*34848Sminshall ring_empty_consecutive(), 81*34848Sminshall ring_full_count(), 82*34848Sminshall ring_full_consecutive(); 8332380Sminshall #endif /* defined(LINT_ARGS) */ 84