aboutsummaryrefslogtreecommitdiff
path: root/src/rt/circular_buffer.cpp
diff options
context:
space:
mode:
authorBrian Anderson <[email protected]>2011-01-07 22:22:35 -0500
committerGraydon Hoare <[email protected]>2011-01-10 11:31:33 -0800
commitf1df1d1a51f310553fd8bcb831215307ec2609ae (patch)
tree2fc8794122293e1bfd4c59a8f19f1c0eabdfd448 /src/rt/circular_buffer.cpp
parentDon't allow circular_buffer to shrink below it's initial size (diff)
downloadrust-f1df1d1a51f310553fd8bcb831215307ec2609ae.tar.xz
rust-f1df1d1a51f310553fd8bcb831215307ec2609ae.zip
Don't allow circular_buffer to shrink below its original size when unit_sz is not a power of two
Diffstat (limited to 'src/rt/circular_buffer.cpp')
-rw-r--r--src/rt/circular_buffer.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/rt/circular_buffer.cpp b/src/rt/circular_buffer.cpp
index 8f12a115..b458dedd 100644
--- a/src/rt/circular_buffer.cpp
+++ b/src/rt/circular_buffer.cpp
@@ -15,8 +15,9 @@ is_power_of_two(size_t value) {
circular_buffer::circular_buffer(rust_dom *dom, size_t unit_sz) :
dom(dom),
unit_sz(unit_sz),
- _buffer_sz(next_power_of_two(
+ _initial_sz(next_power_of_two(
INITIAL_CIRCULAR_BUFFFER_SIZE_IN_UNITS * unit_sz)),
+ _buffer_sz(_initial_sz),
_next(0),
_unread(0),
_buffer((uint8_t *)dom->calloc(_buffer_sz)) {
@@ -121,15 +122,13 @@ circular_buffer::dequeue(void *dst) {
}
// Shrink if possible.
- if (_buffer_sz > INITIAL_CIRCULAR_BUFFFER_SIZE_IN_UNITS * unit_sz &&
- _unread <= _buffer_sz / 4) {
+ if (_buffer_sz > _initial_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));
+ I(dom, _initial_sz <= _buffer_sz);
dom->free(_buffer);
_buffer = (uint8_t *)tmp;
_next = 0;