File tree Expand file tree Collapse file tree 4 files changed +26
-8
lines changed Expand file tree Collapse file tree 4 files changed +26
-8
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 5f05ae68e555e94aa31c36b35dfb2e03952443ba
2
+ refs/heads/master: f1df1d1a51f310553fd8bcb831215307ec2609ae
Original file line number Diff line number Diff line change @@ -15,8 +15,9 @@ is_power_of_two(size_t value) {
15
15
circular_buffer::circular_buffer (rust_dom *dom, size_t unit_sz) :
16
16
dom(dom),
17
17
unit_sz(unit_sz),
18
- _buffer_sz (next_power_of_two(
18
+ _initial_sz (next_power_of_two(
19
19
INITIAL_CIRCULAR_BUFFFER_SIZE_IN_UNITS * unit_sz)),
20
+ _buffer_sz(_initial_sz),
20
21
_next(0 ),
21
22
_unread(0 ),
22
23
_buffer((uint8_t *)dom->calloc(_buffer_sz)) {
@@ -121,15 +122,13 @@ circular_buffer::dequeue(void *dst) {
121
122
}
122
123
123
124
// 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 ) {
126
126
dom->log (rust_log::MEM | rust_log::COMM,
127
127
" circular_buffer is shrinking to %d bytes" , _buffer_sz / 2 );
128
128
void *tmp = dom->malloc (_buffer_sz / 2 );
129
129
transfer (tmp);
130
130
_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);
133
132
dom->free (_buffer);
134
133
_buffer = (uint8_t *)tmp;
135
134
_next = 0 ;
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ circular_buffer : public dom_owned<circular_buffer> {
24
24
size_t size ();
25
25
26
26
private:
27
+ // Initial size of the buffer in bytes.
28
+ size_t _initial_sz;
29
+
27
30
// Size of the buffer in bytes, should always be a power of two so that
28
31
// modulo arithmetic (x % _buffer_sz) can optimized away with
29
32
// (x & (_buffer_sz - 1)).
Original file line number Diff line number Diff line change @@ -39,18 +39,34 @@ impure fn test_grow() {
39
39
}
40
40
41
41
// Don't allow the buffer to shrink below it's original size
42
- impure fn test_shrink ( ) {
42
+ impure fn test_shrink1 ( ) {
43
43
let port[ i8] myport = port ( ) ;
44
44
auto mychan = chan ( myport) ;
45
45
46
46
mychan <| 0i8 ;
47
47
auto x <- myport;
48
48
}
49
49
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( 0 u, 100 u) ) {
57
+ mychan <| val;
58
+ }
59
+
60
+ for each ( uint i in _uint. range( 0 u, 100 u) ) {
61
+ auto x <- myport;
62
+ }
63
+ }
64
+
50
65
impure fn main ( ) {
51
66
test_init ( ) ;
52
67
test_grow ( ) ;
53
- test_shrink ( ) ;
68
+ test_shrink1 ( ) ;
69
+ test_shrink2 ( ) ;
54
70
}
55
71
56
72
// Local Variables:
You can’t perform that action at this time.
0 commit comments