Commit | Line | Data |
---|---|---|
897ce52e KB |
1 | /* |
2 | * Copyright (c) 1988 Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
cb956e54 | 5 | * %sccs.include.redist.c% |
897ce52e | 6 | * |
15d31b7e | 7 | * @(#)ring.h 5.2 (Berkeley) %G% |
897ce52e KB |
8 | */ |
9 | ||
15d31b7e DB |
10 | #if defined(P) |
11 | # undef P | |
12 | #endif | |
13 | ||
14 | #if defined(__STDC__) || defined(LINT_ARGS) | |
15 | # define P(x) x | |
16 | #else | |
17 | # define P(x) () | |
18 | #endif | |
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 { | |
15d31b7e DB |
31 | unsigned 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 | #if defined(ENCRYPT) | |
37 | unsigned char *clearto; /* Data to this point is clear text */ | |
38 | unsigned char *encryyptedto; /* Data is encrypted to here */ | |
39 | #endif | |
097761fd | 40 | int size; /* size in bytes of buffer */ |
8b6750f5 GM |
41 | u_long consumetime, /* help us keep straight full, empty, etc. */ |
42 | supplytime; | |
097761fd GM |
43 | } Ring; |
44 | ||
45 | /* Here are some functions and macros to deal with the ring buffer */ | |
46 | ||
115a5494 GM |
47 | /* Initialization routine */ |
48 | extern int | |
15d31b7e | 49 | ring_init P((Ring *ring, unsigned char *buffer, int count)); |
115a5494 | 50 | |
097761fd GM |
51 | /* Data movement routines */ |
52 | extern void | |
15d31b7e | 53 | ring_supply_data P((Ring *ring, unsigned char *buffer, int count)); |
4a8a7128 PB |
54 | #ifdef notdef |
55 | extern void | |
15d31b7e | 56 | ring_consume_data P((Ring *ring, unsigned char *buffer, int count)); |
4a8a7128 | 57 | #endif |
097761fd GM |
58 | |
59 | /* Buffer state transition routines */ | |
60 | extern void | |
15d31b7e DB |
61 | ring_supplied P((Ring *ring, int count)), |
62 | ring_consumed P((Ring *ring, int count)); | |
097761fd GM |
63 | |
64 | /* Buffer state query routines */ | |
65 | extern int | |
15d31b7e DB |
66 | ring_empty_count P((Ring *ring)), |
67 | ring_empty_consecutive P((Ring *ring)), | |
68 | ring_full_count P((Ring *ring)), | |
69 | ring_full_consecutive P((Ring *ring)); | |
097761fd | 70 | |
15d31b7e | 71 | #if defined(ENCRYPT) |
4a8a7128 | 72 | extern void |
15d31b7e DB |
73 | ring_encrypt P((Ring *ring, void (*func)())), |
74 | ring_clearto P((Ring *ring)); | |
4a8a7128 | 75 | #endif |
80a47e22 | 76 | |
80a47e22 GM |
77 | extern void |
78 | ring_clear_mark(), | |
79 | ring_mark(); |