Skip to content

Commit d4410a9

Browse files
committed
rewrite to use old C++-based mechanism
1 parent a1ef79c commit d4410a9

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/libcore/task.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ Example:
2828
*/
2929
import cast = unsafe::reinterpret_cast;
3030
import comm;
31-
import option::{some, none};
32-
import option = option::t;
3331
import ptr;
3432
import c = ctypes;
3533

@@ -112,10 +110,23 @@ Returns:
112110
113111
A handle to the new task
114112
*/
115-
fn spawn(-f: sendfn()) -> task unsafe {
113+
fn spawn(-f: sendfn()) -> task {
114+
spawn_inner(f, none)
115+
}
116+
117+
fn spawn_inner(-f: sendfn(),
118+
notify: option<comm::chan<task_notification>>) -> task unsafe {
116119
let closure: *rust_closure = unsafe::reinterpret_cast(ptr::addr_of(f));
117120
#debug("spawn: closure={%x,%x}", (*closure).fnptr, (*closure).envptr);
118121
let id = rustrt::new_task();
122+
123+
// set up notifications if they are enabled.
124+
option::may(notify) {|c|
125+
let task_ptr <- rust_task_ptr(rustrt::get_task_pointer(id));
126+
(**task_ptr).notify_enabled = 1;
127+
(**task_ptr).notify_chan = c;
128+
}
129+
119130
rustrt::start_task(id, closure);
120131
unsafe::leak(f);
121132
ret id;
@@ -129,6 +140,11 @@ A task that sends notification upon termination
129140
type joinable_task = (task, comm::port<task_notification>);
130141

131142
fn spawn_joinable(-f: sendfn()) -> joinable_task {
143+
let notify_port = comm::port();
144+
let notify_chan = comm::chan(notify_port);
145+
let task = spawn_inner(f, some(notify_chan));
146+
ret (task, notify_port);
147+
/*
132148
resource notify_rsrc(data: (comm::chan<task_notification>,
133149
task,
134150
@mutable task_result)) {
@@ -148,6 +164,7 @@ fn spawn_joinable(-f: sendfn()) -> joinable_task {
148164
};
149165
let task = spawn(g);
150166
ret (task, notify_port);
167+
*/
151168
}
152169

153170
/*

src/test/bench/task-perf-spawnalot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn f(&&n: uint) {
1212
}
1313
}
1414

15-
fn g(&&_i: ()) { }
15+
fn g() { }
1616

1717
fn main(args: [str]) {
1818
let n =

src/test/bench/task-perf-word-count.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,12 @@ mod map_reduce {
7171
[joinable_task] {
7272
let tasks = [];
7373
for i: str in inputs {
74-
tasks += [task::spawn_joinable((ctrl, i), map_task)];
74+
tasks += [task::spawn_joinable {|| map_task(ctrl, i)}];
7575
}
7676
ret tasks;
7777
}
7878

79-
fn map_task(args: (chan<ctrl_proto>, str)) {
80-
let (ctrl, input) = args;
79+
fn map_task(ctrl: chan<ctrl_proto>, input: str) {
8180
// log(error, "map_task " + input);
8281
let intermediates = map::new_str_hash();
8382

@@ -106,8 +105,7 @@ mod map_reduce {
106105
send(ctrl, mapper_done);
107106
}
108107

109-
fn reduce_task(args: (str, chan<chan<reduce_proto>>)) {
110-
let (key, out) = args;
108+
fn reduce_task(key: str, out: chan<chan<reduce_proto>>) {
111109
let p = port();
112110

113111
send(out, chan(p));
@@ -168,8 +166,9 @@ mod map_reduce {
168166
none. {
169167
// log(error, "creating new reducer for " + k);
170168
let p = port();
169+
let ch = chan(p);
171170
tasks +=
172-
[task::spawn_joinable((k, chan(p)), reduce_task)];
171+
[task::spawn_joinable{||reduce_task(k, ch)}];
173172
c = recv(p);
174173
reducers.insert(k, c);
175174
}

0 commit comments

Comments
 (0)