aboutsummaryrefslogtreecommitdiff
path: root/src/rt/circular_buffer.cpp
diff options
context:
space:
mode:
authorBrian Anderson <[email protected]>2011-01-07 23:35:29 -0500
committerGraydon Hoare <[email protected]>2011-01-10 11:31:33 -0800
commit4841c9f3f831c3856f4ea064f29ce5d180150362 (patch)
tree3126f4454d918f7c5fa13bc2b9c317f5becc2323 /src/rt/circular_buffer.cpp
parentRename test to reflect that the circular_buffer runtime class is what's being... (diff)
downloadrust-4841c9f3f831c3856f4ea064f29ce5d180150362.tar.xz
rust-4841c9f3f831c3856f4ea064f29ce5d180150362.zip
Cleanup circular_buffer grow / shrink routines
Diffstat (limited to 'src/rt/circular_buffer.cpp')
-rw-r--r--src/rt/circular_buffer.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/rt/circular_buffer.cpp b/src/rt/circular_buffer.cpp
index 54898fb7..247e494f 100644
--- a/src/rt/circular_buffer.cpp
+++ b/src/rt/circular_buffer.cpp
@@ -66,6 +66,8 @@ circular_buffer::enqueue(void *src) {
if (_next + _unread + unit_sz > _buffer_sz) {
size_t new_buffer_sz = _buffer_sz << 1;
I(dom, new_buffer_sz <= MAX_CIRCULAR_BUFFFER_SIZE);
+ dom->log(rust_log::MEM | rust_log::COMM,
+ "circular_buffer is growing to %d bytes", new_buffer_sz);
void *new_buffer = dom->malloc(new_buffer_sz);
transfer(new_buffer);
dom->free(_buffer);
@@ -124,15 +126,16 @@ circular_buffer::dequeue(void *dst) {
// Shrink if possible.
if (_buffer_sz > _initial_sz && _unread <= _buffer_sz / 4) {
+ size_t new_buffer_sz = _buffer_sz >> 1;
+ I(dom, _initial_sz <= new_buffer_sz);
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);
+ "circular_buffer is shrinking to %d bytes", new_buffer_sz);
+ void *tmp = dom->malloc(new_buffer_sz);
transfer(tmp);
- _buffer_sz >>= 1;
- I(dom, _initial_sz <= _buffer_sz);
dom->free(_buffer);
_buffer = (uint8_t *)tmp;
_next = 0;
+ _buffer_sz = new_buffer_sz;
}
}