11e4bc969Sminshall /* 2*58ab6e53Sminshall * This defines a structure for a ring buffer. 31e4bc969Sminshall * 4*58ab6e53Sminshall * The circular buffer has two parts: 51e4bc969Sminshall *((( 6*58ab6e53Sminshall * full: [consume, supply) 7*58ab6e53Sminshall * empty: [supply, consume) 81e4bc969Sminshall *]]] 91e4bc969Sminshall * 101e4bc969Sminshall */ 111e4bc969Sminshall typedef struct { 12*58ab6e53Sminshall char *consume, /* where data comes out of */ 13*58ab6e53Sminshall *supply, /* where data comes in to */ 141e4bc969Sminshall *bottom, /* lowest address in buffer */ 151e4bc969Sminshall *top; /* highest address+1 in buffer */ 161e4bc969Sminshall int size; /* size in bytes of buffer */ 17*58ab6e53Sminshall u_long consumetime, /* help us keep straight full, empty, etc. */ 18*58ab6e53Sminshall supplytime; 191e4bc969Sminshall } Ring; 201e4bc969Sminshall 211e4bc969Sminshall /* Here are some functions and macros to deal with the ring buffer */ 221e4bc969Sminshall 231e4bc969Sminshall 241e4bc969Sminshall #if defined(LINT_ARGS) 251e4bc969Sminshall 2601ec75b3Sminshall /* Initialization routine */ 2701ec75b3Sminshall extern int 2801ec75b3Sminshall ring_init(Ring *ring, char *buffer, int count); 2901ec75b3Sminshall 301e4bc969Sminshall /* Data movement routines */ 311e4bc969Sminshall extern void 32*58ab6e53Sminshall ring_supply_data(Ring *ring, char *buffer, int count), 33*58ab6e53Sminshall ring_consume_data(Ring *ring, char *buffer, int count); 341e4bc969Sminshall 351e4bc969Sminshall /* Buffer state transition routines */ 361e4bc969Sminshall extern void 37*58ab6e53Sminshall ring_supplied(Ring *ring, int count), 38*58ab6e53Sminshall ring_consumed(Ring *ring, int count); 391e4bc969Sminshall 401e4bc969Sminshall /* Buffer state query routines */ 411e4bc969Sminshall extern int 421e4bc969Sminshall ring_empty_count(Ring *ring), 431e4bc969Sminshall ring_empty_consecutive(Ring *ring), 44*58ab6e53Sminshall ring_full_count(Ring *ring), 45*58ab6e53Sminshall ring_full_consecutive(Ring *ring); 461e4bc969Sminshall 471e4bc969Sminshall #endif /* defined(LINT_ARGS) */ 48