Skip to content

Commit 315395e

Browse files
committed
---
yaml --- r: 72146 b: refs/heads/dist-snap c: 6773b63 h: refs/heads/master v: v3
1 parent ad00066 commit 315395e

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: b50030718cf28f2a5a81857a26b57442734fe854
10-
refs/heads/dist-snap: b96765179ec16bc306bf0f1cc76c7ff67ea36670
10+
refs/heads/dist-snap: 6773b63671081c722761d3980393642452c08157
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libcore/task/mod.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub struct TaskOpts {
175175
// FIXME (#3724): Replace the 'consumed' bit with move mode on self
176176
pub struct TaskBuilder {
177177
opts: TaskOpts,
178-
gen_body: @fn(v: ~fn()) -> ~fn(),
178+
mut gen_body: Option<~fn(v: ~fn()) -> ~fn()>,
179179
can_not_copy: Option<util::NonCopyable>,
180180
mut consumed: bool,
181181
}
@@ -188,7 +188,7 @@ pub struct TaskBuilder {
188188
pub fn task() -> TaskBuilder {
189189
TaskBuilder {
190190
opts: default_task_opts(),
191-
gen_body: |body| body, // Identity function
191+
gen_body: None,
192192
can_not_copy: None,
193193
mut consumed: false,
194194
}
@@ -201,6 +201,7 @@ priv impl TaskBuilder {
201201
fail!(~"Cannot copy a task_builder"); // Fake move mode on self
202202
}
203203
self.consumed = true;
204+
let gen_body = replace(&mut self.gen_body, None);
204205
let notify_chan = replace(&mut self.opts.notify_chan, None);
205206
TaskBuilder {
206207
opts: TaskOpts {
@@ -209,7 +210,7 @@ priv impl TaskBuilder {
209210
notify_chan: notify_chan,
210211
sched: self.opts.sched
211212
},
212-
gen_body: self.gen_body,
213+
gen_body: gen_body,
213214
can_not_copy: None,
214215
consumed: false
215216
}
@@ -341,8 +342,23 @@ pub impl TaskBuilder {
341342
* generator by applying the task body which results from the
342343
* existing body generator to the new body generator.
343344
*/
344-
fn add_wrapper(&self, wrapper: @fn(v: ~fn()) -> ~fn()) -> TaskBuilder {
345-
let prev_gen_body = self.gen_body;
345+
fn add_wrapper(&self, wrapper: ~fn(v: ~fn()) -> ~fn()) -> TaskBuilder {
346+
let prev_gen_body = replace(&mut self.gen_body, None);
347+
let prev_gen_body = match prev_gen_body {
348+
Some(gen) => gen,
349+
None => {
350+
let f: ~fn(~fn()) -> ~fn() = |body| body;
351+
f
352+
}
353+
};
354+
let prev_gen_body = Cell(prev_gen_body);
355+
let next_gen_body = {
356+
let f: ~fn(~fn()) -> ~fn() = |body| {
357+
let prev_gen_body = prev_gen_body.take();
358+
wrapper(prev_gen_body(body))
359+
};
360+
f
361+
};
346362
let notify_chan = replace(&mut self.opts.notify_chan, None);
347363
TaskBuilder {
348364
opts: TaskOpts {
@@ -351,7 +367,7 @@ pub impl TaskBuilder {
351367
notify_chan: notify_chan,
352368
sched: self.opts.sched
353369
},
354-
gen_body: |body| { wrapper(prev_gen_body(body)) },
370+
gen_body: Some(next_gen_body),
355371
can_not_copy: None,
356372
.. self.consume()
357373
}
@@ -370,6 +386,7 @@ pub impl TaskBuilder {
370386
* must be greater than zero.
371387
*/
372388
fn spawn(&self, f: ~fn()) {
389+
let gen_body = replace(&mut self.gen_body, None);
373390
let notify_chan = replace(&mut self.opts.notify_chan, None);
374391
let x = self.consume();
375392
let opts = TaskOpts {
@@ -378,7 +395,15 @@ pub impl TaskBuilder {
378395
notify_chan: notify_chan,
379396
sched: x.opts.sched
380397
};
381-
spawn::spawn_raw(opts, (x.gen_body)(f));
398+
let f = match gen_body {
399+
Some(gen) => {
400+
gen(f)
401+
}
402+
None => {
403+
f
404+
}
405+
};
406+
spawn::spawn_raw(opts, f);
382407
}
383408
/// Runs a task, while transfering ownership of one argument to the child.
384409
fn spawn_with<A:Owned>(&self, arg: A, f: ~fn(v: A)) {

0 commit comments

Comments
 (0)