Commit | Line | Data |
---|---|---|
897ce52e KB |
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 | |
b36fc510 KB |
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. | |
897ce52e | 16 | * |
b36fc510 | 17 | * @(#)ring.h 1.8 (Berkeley) %G% |
897ce52e KB |
18 | */ |
19 | ||
097761fd | 20 | /* |
8b6750f5 | 21 | * This defines a structure for a ring buffer. |
097761fd | 22 | * |
8b6750f5 | 23 | * The circular buffer has two parts: |
097761fd | 24 | *((( |
8b6750f5 GM |
25 | * full: [consume, supply) |
26 | * empty: [supply, consume) | |
097761fd GM |
27 | *]]] |
28 | * | |
097761fd GM |
29 | */ |
30 | typedef struct { | |
8b6750f5 GM |
31 | char *consume, /* where data comes out of */ |
32 | *supply, /* where data comes in to */ | |
097761fd | 33 | *bottom, /* lowest address in buffer */ |
218b1a4c GM |
34 | *top, /* highest address+1 in buffer */ |
35 | *mark; /* marker (user defined) */ | |
097761fd | 36 | int size; /* size in bytes of buffer */ |
8b6750f5 GM |
37 | u_long consumetime, /* help us keep straight full, empty, etc. */ |
38 | supplytime; | |
097761fd GM |
39 | } Ring; |
40 | ||
41 | /* Here are some functions and macros to deal with the ring buffer */ | |
42 | ||
43 | ||
44 | #if defined(LINT_ARGS) | |
45 | ||
115a5494 GM |
46 | /* Initialization routine */ |
47 | extern int | |
48 | ring_init(Ring *ring, char *buffer, int count); | |
49 | ||
097761fd GM |
50 | /* Data movement routines */ |
51 | extern void | |
8b6750f5 GM |
52 | ring_supply_data(Ring *ring, char *buffer, int count), |
53 | ring_consume_data(Ring *ring, char *buffer, int count); | |
097761fd GM |
54 | |
55 | /* Buffer state transition routines */ | |
56 | extern void | |
8b6750f5 GM |
57 | ring_supplied(Ring *ring, int count), |
58 | ring_consumed(Ring *ring, int count); | |
097761fd GM |
59 | |
60 | /* Buffer state query routines */ | |
61 | extern int | |
62 | ring_empty_count(Ring *ring), | |
63 | ring_empty_consecutive(Ring *ring), | |
8b6750f5 GM |
64 | ring_full_count(Ring *ring), |
65 | ring_full_consecutive(Ring *ring); | |
097761fd | 66 | |
80a47e22 GM |
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(); | |
097761fd | 88 | #endif /* defined(LINT_ARGS) */ |