Skip to content

Commit 490000c

Browse files
committed
---
yaml --- r: 6895 b: refs/heads/master c: aeadc62 h: refs/heads/master i: 6893: 267bc32 6891: 24c2731 6887: 623263f 6879: 33d5312 v: v3
1 parent 5850f6c commit 490000c

File tree

6 files changed

+89
-2
lines changed

6 files changed

+89
-2
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 128621be97d425a1d19e6640c8aee4fb6fca430b
2+
refs/heads/master: aeadc6269ef76f4425a49d892ceac7ea311ef5c1

trunk/src/libcore/core.rs

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import option::{some, none};
77
import option = option::t;
88
export option, some, none;
9+
export repeat;
910

1011
// Export the log levels as global constants. Higher levels mean
1112
// more-verbosity. Error is the bottom level, default logging level is
@@ -15,3 +16,16 @@ const error : int = 0;
1516
const warn : int = 1;
1617
const info : int = 2;
1718
const debug : int = 3;
19+
20+
/*
21+
Function: repeat
22+
23+
Execute a function for a set number of times
24+
*/
25+
fn repeat(times: uint, f: block()) {
26+
let i = 0u;
27+
while i < times {
28+
f();
29+
i += 1u;
30+
}
31+
}

trunk/src/rt/circular_buffer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class
99
circular_buffer : public kernel_owned<circular_buffer> {
10-
static const size_t INITIAL_CIRCULAR_BUFFER_SIZE_IN_UNITS = 8;
10+
static const size_t INITIAL_CIRCULAR_BUFFER_SIZE_IN_UNITS = 1;
1111
static const size_t MAX_CIRCULAR_BUFFER_SIZE = 1 << 24;
1212

1313
public:

trunk/src/rt/rust_task.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ rust_task::yield(size_t time_in_us, bool *killed) {
404404
*killed = true;
405405
}
406406

407+
// We're not going to need any extra stack for a while
408+
clear_stack_cache();
409+
407410
yield_timer.reset_us(time_in_us);
408411

409412
// Return to the scheduler.
@@ -746,6 +749,15 @@ rust_task::del_stack() {
746749
record_stack_limit();
747750
}
748751

752+
void
753+
rust_task::clear_stack_cache() {
754+
A(sched, stk != NULL, "Expected to have a stack");
755+
if (stk->prev != NULL) {
756+
free_stk(this, stk->prev);
757+
stk->prev = NULL;
758+
}
759+
}
760+
749761
void
750762
rust_task::record_stack_limit() {
751763
// The function prolog compares the amount of stack needed to the end of

trunk/src/rt/rust_task.h

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ rust_task : public kernel_owned<rust_task>, rust_cond
203203
void reset_stack_limit();
204204
bool on_rust_stack();
205205
void check_stack_canary();
206+
void clear_stack_cache();
206207
};
207208

208209
//
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// xfail-test FIXME: Can't run under valgrind - too much RAM
2+
// FIXME: This doesn't spawn close to a million tasks yet
3+
4+
tag msg {
5+
ready(comm::chan<msg>);
6+
start;
7+
done(int);
8+
}
9+
10+
fn calc(&&args: (int, comm::chan<msg>)) {
11+
let (depth, parent_ch) = args;
12+
let port = comm::port();
13+
let children = depth > 0 ? 20u : 0u;
14+
let child_chs = [];
15+
let sum = 0;
16+
17+
repeat (children) {||
18+
task::spawn((depth - 1, comm::chan(port)), calc);
19+
}
20+
21+
repeat (children) {||
22+
alt comm::recv(port) {
23+
ready(child_ch) {
24+
child_chs += [child_ch];
25+
}
26+
}
27+
}
28+
29+
comm::send(parent_ch, ready(comm::chan(port)));
30+
31+
alt comm::recv(port) {
32+
start. {
33+
vec::iter (child_chs) { |child_ch|
34+
comm::send(child_ch, start);
35+
}
36+
}
37+
}
38+
39+
repeat (children) {||
40+
alt comm::recv(port) {
41+
done(child_sum) { sum += child_sum; }
42+
}
43+
}
44+
45+
comm::send(parent_ch, done(sum + 1));
46+
}
47+
48+
fn main() {
49+
let port = comm::port();
50+
task::spawn((3, comm::chan(port)), calc);
51+
alt comm::recv(port) {
52+
ready(chan) {
53+
comm::send(chan, start);
54+
}
55+
}
56+
let sum = alt comm::recv(port) {
57+
done(sum) { sum }
58+
};
59+
log #fmt("How many tasks? That's right, %d tasks.", sum);
60+
}

0 commit comments

Comments
 (0)