| 1 | /* |
| 2 | * Copyright (c) 1988 Regents of the University of California. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms are permitted |
| 6 | * provided that the above copyright notice and this paragraph are |
| 7 | * duplicated in all such forms and that any documentation, |
| 8 | * advertising materials, and other materials related to such |
| 9 | * distribution and use acknowledge that the software was developed |
| 10 | * by the University of California, Berkeley. The name of the |
| 11 | * University may not be used to endorse or promote products derived |
| 12 | * from this software without specific prior written permission. |
| 13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
| 14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
| 15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 16 | * |
| 17 | * @(#)ring.h 1.8 (Berkeley) %G% |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * This defines a structure for a ring buffer. |
| 22 | * |
| 23 | * The circular buffer has two parts: |
| 24 | *((( |
| 25 | * full: [consume, supply) |
| 26 | * empty: [supply, consume) |
| 27 | *]]] |
| 28 | * |
| 29 | */ |
| 30 | typedef struct { |
| 31 | char *consume, /* where data comes out of */ |
| 32 | *supply, /* where data comes in to */ |
| 33 | *bottom, /* lowest address in buffer */ |
| 34 | *top, /* highest address+1 in buffer */ |
| 35 | *mark; /* marker (user defined) */ |
| 36 | int size; /* size in bytes of buffer */ |
| 37 | u_long consumetime, /* help us keep straight full, empty, etc. */ |
| 38 | supplytime; |
| 39 | } Ring; |
| 40 | |
| 41 | /* Here are some functions and macros to deal with the ring buffer */ |
| 42 | |
| 43 | |
| 44 | #if defined(LINT_ARGS) |
| 45 | |
| 46 | /* Initialization routine */ |
| 47 | extern int |
| 48 | ring_init(Ring *ring, char *buffer, int count); |
| 49 | |
| 50 | /* Data movement routines */ |
| 51 | extern void |
| 52 | ring_supply_data(Ring *ring, char *buffer, int count), |
| 53 | ring_consume_data(Ring *ring, char *buffer, int count); |
| 54 | |
| 55 | /* Buffer state transition routines */ |
| 56 | extern void |
| 57 | ring_supplied(Ring *ring, int count), |
| 58 | ring_consumed(Ring *ring, int count); |
| 59 | |
| 60 | /* Buffer state query routines */ |
| 61 | extern int |
| 62 | ring_empty_count(Ring *ring), |
| 63 | ring_empty_consecutive(Ring *ring), |
| 64 | ring_full_count(Ring *ring), |
| 65 | ring_full_consecutive(Ring *ring); |
| 66 | |
| 67 | #else /* LINT_ARGS */ |
| 68 | extern int |
| 69 | ring_init(); |
| 70 | |
| 71 | extern void |
| 72 | ring_supply_data(), |
| 73 | ring_consume_data(); |
| 74 | |
| 75 | extern void |
| 76 | ring_supplied(), |
| 77 | ring_consumed(); |
| 78 | |
| 79 | extern void |
| 80 | ring_clear_mark(), |
| 81 | ring_mark(); |
| 82 | |
| 83 | extern int |
| 84 | ring_empty_count(), |
| 85 | ring_empty_consecutive(), |
| 86 | ring_full_count(), |
| 87 | ring_full_consecutive(); |
| 88 | #endif /* defined(LINT_ARGS) */ |