aboutsummaryrefslogtreecommitdiff
path: root/src/rt/circular_buffer.cpp
diff options
context:
space:
mode:
authorMichael Bebenita <[email protected]>2010-07-28 00:03:47 -0700
committerGraydon Hoare <[email protected]>2010-07-28 20:30:29 -0700
commitdbcc9b36b148857c17ced736cfc93dc8883038db (patch)
tree544fa81ac8d90a068e5b7f981d01a173a6a4704c /src/rt/circular_buffer.cpp
parentChange unread-on-destroy condition for circular buffer to merely a warning. (diff)
downloadrust-dbcc9b36b148857c17ced736cfc93dc8883038db.tar.xz
rust-dbcc9b36b148857c17ced736cfc93dc8883038db.zip
Let circular buffers actually grow to max sz, reset _next when resizing.
Diffstat (limited to 'src/rt/circular_buffer.cpp')
-rw-r--r--src/rt/circular_buffer.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/rt/circular_buffer.cpp b/src/rt/circular_buffer.cpp
index 101d0176..a93f2572 100644
--- a/src/rt/circular_buffer.cpp
+++ b/src/rt/circular_buffer.cpp
@@ -63,12 +63,14 @@ circular_buffer::enqueue(void *src) {
// Grow if necessary.
if (_unread == _buffer_sz) {
- I(dom, _buffer_sz <= MAX_CIRCULAR_BUFFFER_SIZE);
- void *tmp = dom->malloc(_buffer_sz << 1);
- transfer(tmp);
- _buffer_sz <<= 1;
+ size_t new_buffer_sz = _buffer_sz << 1;
+ I(dom, new_buffer_sz <= MAX_CIRCULAR_BUFFFER_SIZE);
+ void *new_buffer = dom->malloc(new_buffer_sz);
+ transfer(new_buffer);
dom->free(_buffer);
- _buffer = (uint8_t *)tmp;
+ _buffer = (uint8_t *)new_buffer;
+ _next = 0;
+ _buffer_sz = new_buffer_sz;
}
dom->log(rust_log::MEM | rust_log::COMM,