Skip to content

Commit fe6af48

Browse files
brsongraydon
authored andcommitted
---
yaml --- r: 1214 b: refs/heads/master c: f1df1d1 h: refs/heads/master v: v3
1 parent e962951 commit fe6af48

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 5f05ae68e555e94aa31c36b35dfb2e03952443ba
2+
refs/heads/master: f1df1d1a51f310553fd8bcb831215307ec2609ae

trunk/src/rt/circular_buffer.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ is_power_of_two(size_t value) {
1515
circular_buffer::circular_buffer(rust_dom *dom, size_t unit_sz) :
1616
dom(dom),
1717
unit_sz(unit_sz),
18-
_buffer_sz(next_power_of_two(
18+
_initial_sz(next_power_of_two(
1919
INITIAL_CIRCULAR_BUFFFER_SIZE_IN_UNITS * unit_sz)),
20+
_buffer_sz(_initial_sz),
2021
_next(0),
2122
_unread(0),
2223
_buffer((uint8_t *)dom->calloc(_buffer_sz)) {
@@ -121,15 +122,13 @@ circular_buffer::dequeue(void *dst) {
121122
}
122123

123124
// Shrink if possible.
124-
if (_buffer_sz > INITIAL_CIRCULAR_BUFFFER_SIZE_IN_UNITS * unit_sz &&
125-
_unread <= _buffer_sz / 4) {
125+
if (_buffer_sz > _initial_sz && _unread <= _buffer_sz / 4) {
126126
dom->log(rust_log::MEM | rust_log::COMM,
127127
"circular_buffer is shrinking to %d bytes", _buffer_sz / 2);
128128
void *tmp = dom->malloc(_buffer_sz / 2);
129129
transfer(tmp);
130130
_buffer_sz >>= 1;
131-
I(dom, _buffer_sz >=
132-
next_power_of_two(INITIAL_CIRCULAR_BUFFFER_SIZE_IN_UNITS * unit_sz));
131+
I(dom, _initial_sz <= _buffer_sz);
133132
dom->free(_buffer);
134133
_buffer = (uint8_t *)tmp;
135134
_next = 0;

trunk/src/rt/circular_buffer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ circular_buffer : public dom_owned<circular_buffer> {
2424
size_t size();
2525

2626
private:
27+
// Initial size of the buffer in bytes.
28+
size_t _initial_sz;
29+
2730
// Size of the buffer in bytes, should always be a power of two so that
2831
// modulo arithmetic (x % _buffer_sz) can optimized away with
2932
// (x & (_buffer_sz - 1)).

trunk/src/test/run-pass/chan-poweroftwo.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,34 @@ impure fn test_grow() {
3939
}
4040

4141
// Don't allow the buffer to shrink below it's original size
42-
impure fn test_shrink() {
42+
impure fn test_shrink1() {
4343
let port[i8] myport = port();
4444
auto mychan = chan(myport);
4545

4646
mychan <| 0i8;
4747
auto x <- myport;
4848
}
4949

50+
impure fn test_shrink2() {
51+
let port[record] myport = port();
52+
auto mychan = chan(myport);
53+
54+
let record val = rec(val1=0i32, val2=0i32, val3=0i32);
55+
56+
for each (uint i in _uint.range(0u, 100u)) {
57+
mychan <| val;
58+
}
59+
60+
for each (uint i in _uint.range(0u, 100u)) {
61+
auto x <- myport;
62+
}
63+
}
64+
5065
impure fn main() {
5166
test_init();
5267
test_grow();
53-
test_shrink();
68+
test_shrink1();
69+
test_shrink2();
5470
}
5571

5672
// Local Variables:

0 commit comments

Comments
 (0)