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 | |
6 | * provided that this notice is preserved and that due credit is given | |
7 | * to the University of California at Berkeley. The name of the University | |
8 | * may not be used to endorse or promote products derived from this | |
9 | * software without specific prior written permission. This software | |
10 | * is provided ``as is'' without express or implied warranty. | |
11 | * | |
12 | * @(#)ring.h 1.6 (Berkeley) %G% | |
13 | */ | |
14 | ||
097761fd | 15 | /* |
8b6750f5 | 16 | * This defines a structure for a ring buffer. |
097761fd | 17 | * |
8b6750f5 | 18 | * The circular buffer has two parts: |
097761fd | 19 | *((( |
8b6750f5 GM |
20 | * full: [consume, supply) |
21 | * empty: [supply, consume) | |
097761fd GM |
22 | *]]] |
23 | * | |
097761fd GM |
24 | */ |
25 | typedef struct { | |
8b6750f5 GM |
26 | char *consume, /* where data comes out of */ |
27 | *supply, /* where data comes in to */ | |
097761fd | 28 | *bottom, /* lowest address in buffer */ |
218b1a4c GM |
29 | *top, /* highest address+1 in buffer */ |
30 | *mark; /* marker (user defined) */ | |
097761fd | 31 | int size; /* size in bytes of buffer */ |
8b6750f5 GM |
32 | u_long consumetime, /* help us keep straight full, empty, etc. */ |
33 | supplytime; | |
097761fd GM |
34 | } Ring; |
35 | ||
36 | /* Here are some functions and macros to deal with the ring buffer */ | |
37 | ||
38 | ||
39 | #if defined(LINT_ARGS) | |
40 | ||
115a5494 GM |
41 | /* Initialization routine */ |
42 | extern int | |
43 | ring_init(Ring *ring, char *buffer, int count); | |
44 | ||
097761fd GM |
45 | /* Data movement routines */ |
46 | extern void | |
8b6750f5 GM |
47 | ring_supply_data(Ring *ring, char *buffer, int count), |
48 | ring_consume_data(Ring *ring, char *buffer, int count); | |
097761fd GM |
49 | |
50 | /* Buffer state transition routines */ | |
51 | extern void | |
8b6750f5 GM |
52 | ring_supplied(Ring *ring, int count), |
53 | ring_consumed(Ring *ring, int count); | |
097761fd GM |
54 | |
55 | /* Buffer state query routines */ | |
56 | extern int | |
57 | ring_empty_count(Ring *ring), | |
58 | ring_empty_consecutive(Ring *ring), | |
8b6750f5 GM |
59 | ring_full_count(Ring *ring), |
60 | ring_full_consecutive(Ring *ring); | |
097761fd GM |
61 | |
62 | #endif /* defined(LINT_ARGS) */ |