aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian Anderson <[email protected]>2011-01-07 22:13:52 -0500
committerGraydon Hoare <[email protected]>2011-01-10 11:31:32 -0800
commit5f05ae68e555e94aa31c36b35dfb2e03952443ba (patch)
tree191f1ce9c13211830426e3fec63dee59631e6766 /src
parentFix the check for growing the circular_buffer (diff)
downloadrust-5f05ae68e555e94aa31c36b35dfb2e03952443ba.tar.xz
rust-5f05ae68e555e94aa31c36b35dfb2e03952443ba.zip
Don't allow circular_buffer to shrink below it's initial size
Diffstat (limited to 'src')
-rw-r--r--src/rt/circular_buffer.cpp4
-rw-r--r--src/test/run-pass/chan-poweroftwo.rs10
2 files changed, 13 insertions, 1 deletions
diff --git a/src/rt/circular_buffer.cpp b/src/rt/circular_buffer.cpp
index 77509abb..8f12a115 100644
--- a/src/rt/circular_buffer.cpp
+++ b/src/rt/circular_buffer.cpp
@@ -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;
diff --git a/src/test/run-pass/chan-poweroftwo.rs b/src/test/run-pass/chan-poweroftwo.rs
index f3a4b9b5..da9a62cc 100644
--- a/src/test/run-pass/chan-poweroftwo.rs
+++ b/src/test/run-pass/chan-poweroftwo.rs
@@ -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: