version 1.10, 2014/07/20 10:32:23 |
version 1.11, 2014/07/22 07:30:24 |
|
|
((d)->supplytime > (d)->consumetime)) |
((d)->supplytime > (d)->consumetime)) |
|
|
|
|
|
|
|
|
|
|
/* Buffer state transition routines */ |
/* Buffer state transition routines */ |
|
|
void |
void |
ring_init(ring, buffer, count) |
ring_init(Ring *ring, unsigned char *buffer, int count) |
Ring *ring; |
|
unsigned char *buffer; |
|
int count; |
|
{ |
{ |
memset(ring, 0, sizeof *ring); |
memset(ring, 0, sizeof *ring); |
|
|
|
|
* Mark the most recently supplied byte. |
* Mark the most recently supplied byte. |
*/ |
*/ |
|
|
void |
void |
ring_mark(ring) |
ring_mark(Ring *ring) |
Ring *ring; |
|
{ |
{ |
ring->mark = ring_decrement(ring, ring->supply, 1); |
ring->mark = ring_decrement(ring, ring->supply, 1); |
} |
} |
|
|
* Is the ring pointing to the mark? |
* Is the ring pointing to the mark? |
*/ |
*/ |
|
|
int |
int |
ring_at_mark(ring) |
ring_at_mark(Ring *ring) |
Ring *ring; |
|
{ |
{ |
if (ring->mark == ring->consume) { |
if (ring->mark == ring->consume) { |
return 1; |
return 1; |
|
|
* Clear any mark set on the ring. |
* Clear any mark set on the ring. |
*/ |
*/ |
|
|
void |
void |
ring_clear_mark(ring) |
ring_clear_mark(Ring *ring) |
Ring *ring; |
|
{ |
{ |
ring->mark = NULL; |
ring->mark = NULL; |
} |
} |
|
|
/* |
/* |
* Add characters from current segment to ring buffer. |
* Add characters from current segment to ring buffer. |
*/ |
*/ |
void |
void |
ring_supplied(ring, count) |
ring_supplied(Ring *ring, int count) |
Ring *ring; |
|
int count; |
|
{ |
{ |
ring->supply = ring_increment(ring, ring->supply, count); |
ring->supply = ring_increment(ring, ring->supply, count); |
ring->supplytime = ++ring_clock; |
ring->supplytime = ++ring_clock; |
|
|
/* |
/* |
* We have just consumed "c" bytes. |
* We have just consumed "c" bytes. |
*/ |
*/ |
void |
void |
ring_consumed(ring, count) |
ring_consumed(Ring *ring, int count) |
Ring *ring; |
|
int count; |
|
{ |
{ |
if (count == 0) /* don't update anything */ |
if (count == 0) /* don't update anything */ |
return; |
return; |
|
|
} |
} |
|
|
|
|
|
|
/* Buffer state query routines */ |
/* Buffer state query routines */ |
|
|
|
|
/* Number of bytes that may be supplied */ |
/* Number of bytes that may be supplied */ |
int |
int |
ring_empty_count(ring) |
ring_empty_count(Ring *ring) |
Ring *ring; |
|
{ |
{ |
if (ring_empty(ring)) { /* if empty */ |
if (ring_empty(ring)) { /* if empty */ |
return ring->size; |
return ring->size; |
|
|
} |
} |
|
|
/* number of CONSECUTIVE bytes that may be supplied */ |
/* number of CONSECUTIVE bytes that may be supplied */ |
int |
int |
ring_empty_consecutive(ring) |
ring_empty_consecutive(Ring *ring) |
Ring *ring; |
|
{ |
{ |
if ((ring->consume < ring->supply) || ring_empty(ring)) { |
if ((ring->consume < ring->supply) || ring_empty(ring)) { |
/* |
/* |
|
|
* (but don't give more than enough to get to cross over set mark) |
* (but don't give more than enough to get to cross over set mark) |
*/ |
*/ |
|
|
int |
int |
ring_full_count(ring) |
ring_full_count(Ring *ring) |
Ring *ring; |
|
{ |
{ |
if ((ring->mark == NULL) || (ring->mark == ring->consume)) { |
if ((ring->mark == NULL) || (ring->mark == ring->consume)) { |
if (ring_full(ring)) { |
if (ring_full(ring)) { |
|
|
* Return the number of CONSECUTIVE bytes available for consuming. |
* Return the number of CONSECUTIVE bytes available for consuming. |
* However, don't return more than enough to cross over set mark. |
* However, don't return more than enough to cross over set mark. |
*/ |
*/ |
int |
int |
ring_full_consecutive(ring) |
ring_full_consecutive(Ring *ring) |
Ring *ring; |
|
{ |
{ |
if ((ring->mark == NULL) || (ring->mark == ring->consume)) { |
if ((ring->mark == NULL) || (ring->mark == ring->consume)) { |
if ((ring->supply < ring->consume) || ring_full(ring)) { |
if ((ring->supply < ring->consume) || ring_full(ring)) { |
|
|
/* |
/* |
* Move data into the "supply" portion of of the ring buffer. |
* Move data into the "supply" portion of of the ring buffer. |
*/ |
*/ |
void |
void |
ring_supply_data(ring, buffer, count) |
ring_supply_data(Ring *ring, unsigned char *buffer, int count) |
Ring *ring; |
|
unsigned char *buffer; |
|
int count; |
|
{ |
{ |
int i; |
int i; |
|
|