Don't allow circular_buffer to shrink below it's initial size

This commit is contained in:
Brian Anderson 2011-01-07 22:13:52 -05:00 committed by Graydon Hoare
parent 04056d89c8
commit 5f05ae68e5
2 changed files with 13 additions and 1 deletions

View file

@ -121,13 +121,15 @@ circular_buffer::dequeue(void *dst) {
}
// Shrink if possible.
if (_buffer_sz >= INITIAL_CIRCULAR_BUFFFER_SIZE_IN_UNITS * unit_sz &&
if (_buffer_sz > INITIAL_CIRCULAR_BUFFFER_SIZE_IN_UNITS * unit_sz &&
_unread <= _buffer_sz / 4) {
dom->log(rust_log::MEM | rust_log::COMM,
"circular_buffer is shrinking to %d bytes", _buffer_sz / 2);
void *tmp = dom->malloc(_buffer_sz / 2);
transfer(tmp);
_buffer_sz >>= 1;
I(dom, _buffer_sz >=
next_power_of_two(INITIAL_CIRCULAR_BUFFFER_SIZE_IN_UNITS * unit_sz));
dom->free(_buffer);
_buffer = (uint8_t *)tmp;
_next = 0;

View file

@ -38,9 +38,19 @@ impure fn test_grow() {
}
}
// Don't allow the buffer to shrink below it's original size
impure fn test_shrink() {
let port[i8] myport = port();
auto mychan = chan(myport);
mychan <| 0i8;
auto x <- myport;
}
impure fn main() {
test_init();
test_grow();
test_shrink();
}
// Local Variables: