aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Anderson <[email protected]>2011-01-07 01:15:39 -0500
committerGraydon Hoare <[email protected]>2011-01-07 11:34:14 -0800
commita9994a29634cc8d1ce330bdbb41fb1941c41f778 (patch)
tree8900a89ea5a825b1b1102eb06f2fb66517d0ade5
parentFix .gitignore to re-ignore test binaries with new extensions (diff)
downloadrust-a9994a29634cc8d1ce330bdbb41fb1941c41f778.tar.xz
rust-a9994a29634cc8d1ce330bdbb41fb1941c41f778.zip
Correctly initialize circular_buffer to a power-of-two bytes
-rw-r--r--src/rt/circular_buffer.cpp3
-rw-r--r--src/test/run-pass/chan-poweroftwo.rs36
2 files changed, 38 insertions, 1 deletions
diff --git a/src/rt/circular_buffer.cpp b/src/rt/circular_buffer.cpp
index b2eab97e..bdf25124 100644
--- a/src/rt/circular_buffer.cpp
+++ b/src/rt/circular_buffer.cpp
@@ -15,7 +15,8 @@ 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(INITIAL_CIRCULAR_BUFFFER_SIZE_IN_UNITS * unit_sz),
+ _buffer_sz(next_power_of_two(
+ INITIAL_CIRCULAR_BUFFFER_SIZE_IN_UNITS * unit_sz)),
_next(0),
_unread(0),
_buffer((uint8_t *)dom->calloc(_buffer_sz)) {
diff --git a/src/test/run-pass/chan-poweroftwo.rs b/src/test/run-pass/chan-poweroftwo.rs
new file mode 100644
index 00000000..ce2751fa
--- /dev/null
+++ b/src/test/run-pass/chan-poweroftwo.rs
@@ -0,0 +1,36 @@
+// -*- rust -*-
+
+// Regression test for circular_buffer initialization
+
+use std;
+
+import std.option;
+import std._uint;
+import std._vec;
+
+// 12-byte unit for the channel buffer. Assuming that the default
+// buffer size needs to hold 8 units, then the minimum buffer size
+// needs to be 96. That's not a power of two so needs to be rounded up.
+type record = rec(i32 val1, i32 val2, i32 val3);
+
+impure fn worker(chan[record] channel) {
+ let record val = rec(val1=0i32, val2=0i32, val3=0i32);
+ channel <| val;
+}
+
+impure fn main() {
+ let port[record] myport = port();
+ auto mychan = chan(myport);
+
+ auto temp = spawn worker(mychan);
+ auto val <- myport;
+}
+
+// Local Variables:
+// mode: rust;
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End: