Skip to content

Commit 0c2750d

Browse files
committed
---
yaml --- r: 63305 b: refs/heads/snap-stage3 c: fd148cd h: refs/heads/master i: 63303: dfc0cca v: v3
1 parent 9a222c8 commit 0c2750d

File tree

6 files changed

+82
-27
lines changed

6 files changed

+82
-27
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: abc3a8aa1e76f3ecc3930e20453a52681843cec0
4+
refs/heads/snap-stage3: fd148cd3e2d08ce15272f0690f6e41d2e85ee721
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/rt/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub fn start(_argc: int, _argv: **u8, crate_map: *u8, main: ~fn()) -> int {
167167
let sleepers = SleeperList::new();
168168
let mut sched = ~Scheduler::new(loop_, work_queue, sleepers);
169169
sched.no_sleep = true;
170-
let main_task = ~Coroutine::new(&mut sched.stack_pool, main);
170+
let main_task = ~Coroutine::new_root(&mut sched.stack_pool, main);
171171

172172
sched.enqueue_task(main_task);
173173
sched.run();
@@ -241,7 +241,7 @@ fn test_context() {
241241
do run_in_bare_thread {
242242
assert_eq!(context(), GlobalContext);
243243
let mut sched = ~new_test_uv_sched();
244-
let task = ~do Coroutine::new(&mut sched.stack_pool) {
244+
let task = ~do Coroutine::new_root(&mut sched.stack_pool) {
245245
assert_eq!(context(), TaskContext);
246246
let sched = Local::take::<Scheduler>();
247247
do sched.deschedule_running_task_and_then() |sched, task| {

branches/snap-stage3/src/libstd/rt/sched.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,8 @@ impl SchedHandle {
518518
}
519519

520520
pub impl Coroutine {
521-
fn new(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine {
522-
Coroutine::with_task(stack_pool, ~Task::new(), start)
521+
fn new_root(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine {
522+
Coroutine::with_task(stack_pool, ~Task::new_root(), start)
523523
}
524524

525525
fn with_task(stack_pool: &mut StackPool,
@@ -614,7 +614,7 @@ mod test {
614614
let task_ran_ptr: *mut bool = &mut task_ran;
615615

616616
let mut sched = ~new_test_uv_sched();
617-
let task = ~do Coroutine::new(&mut sched.stack_pool) {
617+
let task = ~do Coroutine::new_root(&mut sched.stack_pool) {
618618
unsafe { *task_ran_ptr = true; }
619619
};
620620
sched.enqueue_task(task);
@@ -632,7 +632,7 @@ mod test {
632632

633633
let mut sched = ~new_test_uv_sched();
634634
for int::range(0, total) |_| {
635-
let task = ~do Coroutine::new(&mut sched.stack_pool) {
635+
let task = ~do Coroutine::new_root(&mut sched.stack_pool) {
636636
unsafe { *task_count_ptr = *task_count_ptr + 1; }
637637
};
638638
sched.enqueue_task(task);
@@ -649,10 +649,10 @@ mod test {
649649
let count_ptr: *mut int = &mut count;
650650

651651
let mut sched = ~new_test_uv_sched();
652-
let task1 = ~do Coroutine::new(&mut sched.stack_pool) {
652+
let task1 = ~do Coroutine::new_root(&mut sched.stack_pool) {
653653
unsafe { *count_ptr = *count_ptr + 1; }
654654
let mut sched = Local::take::<Scheduler>();
655-
let task2 = ~do Coroutine::new(&mut sched.stack_pool) {
655+
let task2 = ~do Coroutine::new_root(&mut sched.stack_pool) {
656656
unsafe { *count_ptr = *count_ptr + 1; }
657657
};
658658
// Context switch directly to the new task
@@ -677,7 +677,7 @@ mod test {
677677

678678
let mut sched = ~new_test_uv_sched();
679679

680-
let start_task = ~do Coroutine::new(&mut sched.stack_pool) {
680+
let start_task = ~do Coroutine::new_root(&mut sched.stack_pool) {
681681
run_task(count_ptr);
682682
};
683683
sched.enqueue_task(start_task);
@@ -687,7 +687,7 @@ mod test {
687687

688688
fn run_task(count_ptr: *mut int) {
689689
do Local::borrow::<Scheduler> |sched| {
690-
let task = ~do Coroutine::new(&mut sched.stack_pool) {
690+
let task = ~do Coroutine::new_root(&mut sched.stack_pool) {
691691
unsafe {
692692
*count_ptr = *count_ptr + 1;
693693
if *count_ptr != MAX {
@@ -705,7 +705,7 @@ mod test {
705705
fn test_block_task() {
706706
do run_in_bare_thread {
707707
let mut sched = ~new_test_uv_sched();
708-
let task = ~do Coroutine::new(&mut sched.stack_pool) {
708+
let task = ~do Coroutine::new_root(&mut sched.stack_pool) {
709709
let sched = Local::take::<Scheduler>();
710710
assert!(sched.in_task_context());
711711
do sched.deschedule_running_task_and_then() |sched, task| {
@@ -752,13 +752,13 @@ mod test {
752752
let mut sched1 = ~new_test_uv_sched();
753753
let handle1 = sched1.make_handle();
754754
let handle1_cell = Cell(handle1);
755-
let task1 = ~do Coroutine::new(&mut sched1.stack_pool) {
755+
let task1 = ~do Coroutine::new_root(&mut sched1.stack_pool) {
756756
chan_cell.take().send(());
757757
};
758758
sched1.enqueue_task(task1);
759759

760760
let mut sched2 = ~new_test_uv_sched();
761-
let task2 = ~do Coroutine::new(&mut sched2.stack_pool) {
761+
let task2 = ~do Coroutine::new_root(&mut sched2.stack_pool) {
762762
port_cell.take().recv();
763763
// Release the other scheduler's handle so it can exit
764764
handle1_cell.take();

branches/snap-stage3/src/libstd/rt/task.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct Unwinder {
3737
}
3838

3939
impl Task {
40-
pub fn new() -> Task {
40+
pub fn new_root() -> Task {
4141
Task {
4242
heap: LocalHeap::new(),
4343
gc: GarbageCollector,
@@ -48,7 +48,29 @@ impl Task {
4848
}
4949
}
5050

51-
pub fn without_unwinding() -> Task {
51+
pub fn new_root_without_unwinding() -> Task {
52+
Task {
53+
heap: LocalHeap::new(),
54+
gc: GarbageCollector,
55+
storage: LocalStorage(ptr::null(), None),
56+
logger: StdErrLogger,
57+
unwinder: None,
58+
destroyed: false
59+
}
60+
}
61+
62+
pub fn new_child(&mut self) -> Task {
63+
Task {
64+
heap: LocalHeap::new(),
65+
gc: GarbageCollector,
66+
storage: LocalStorage(ptr::null(), None),
67+
logger: StdErrLogger,
68+
unwinder: Some(Unwinder { unwinding: false }),
69+
destroyed: false
70+
}
71+
}
72+
73+
pub fn new_child_without_unwinding(&mut self) -> Task {
5274
Task {
5375
heap: LocalHeap::new(),
5476
gc: GarbageCollector,

branches/snap-stage3/src/libstd/rt/test.rs

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn run_in_newsched_task(f: ~fn()) {
4848
do run_in_bare_thread {
4949
let mut sched = ~new_test_uv_sched();
5050
let task = ~Coroutine::with_task(&mut sched.stack_pool,
51-
~Task::without_unwinding(),
51+
~Task::new_root_without_unwinding(),
5252
f.take());
5353
sched.enqueue_task(task);
5454
sched.run();
@@ -94,7 +94,7 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
9494

9595
let f_cell = Cell(f_cell.take());
9696
let handles = Cell(handles);
97-
let main_task = ~do Coroutine::new(&mut scheds[0].stack_pool) {
97+
let main_task = ~do Coroutine::new_root(&mut scheds[0].stack_pool) {
9898
f_cell.take()();
9999

100100
let mut handles = handles.take();
@@ -132,9 +132,14 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
132132
pub fn spawntask(f: ~fn()) {
133133
use super::sched::*;
134134

135+
let mut task = None;
136+
do Local::borrow::<Task>() |running_task| {
137+
task = Some(~running_task.new_child_without_unwinding());
138+
}
139+
135140
let mut sched = Local::take::<Scheduler>();
136141
let task = ~Coroutine::with_task(&mut sched.stack_pool,
137-
~Task::without_unwinding(),
142+
task.swap_unwrap(),
138143
f);
139144
sched.schedule_new_task(task);
140145
}
@@ -143,9 +148,14 @@ pub fn spawntask(f: ~fn()) {
143148
pub fn spawntask_immediately(f: ~fn()) {
144149
use super::sched::*;
145150

151+
let mut task = None;
152+
do Local::borrow::<Task>() |running_task| {
153+
task = Some(~running_task.new_child_without_unwinding());
154+
}
155+
146156
let mut sched = Local::take::<Scheduler>();
147157
let task = ~Coroutine::with_task(&mut sched.stack_pool,
148-
~Task::without_unwinding(),
158+
task.swap_unwrap(),
149159
f);
150160
do sched.switch_running_tasks_and_then(task) |sched, task| {
151161
sched.enqueue_task(task);
@@ -156,9 +166,14 @@ pub fn spawntask_immediately(f: ~fn()) {
156166
pub fn spawntask_later(f: ~fn()) {
157167
use super::sched::*;
158168

169+
let mut task = None;
170+
do Local::borrow::<Task>() |running_task| {
171+
task = Some(~running_task.new_child_without_unwinding());
172+
}
173+
159174
let mut sched = Local::take::<Scheduler>();
160175
let task = ~Coroutine::with_task(&mut sched.stack_pool,
161-
~Task::without_unwinding(),
176+
task.swap_unwrap(),
162177
f);
163178

164179
sched.enqueue_task(task);
@@ -170,14 +185,19 @@ pub fn spawntask_random(f: ~fn()) {
170185
use super::sched::*;
171186
use rand::{Rand, rng};
172187

173-
let mut rng = rng();
174-
let run_now: bool = Rand::rand(&mut rng);
188+
let mut task = None;
189+
do Local::borrow::<Task>() |running_task| {
190+
task = Some(~running_task.new_child_without_unwinding());
191+
}
175192

176193
let mut sched = Local::take::<Scheduler>();
177194
let task = ~Coroutine::with_task(&mut sched.stack_pool,
178-
~Task::without_unwinding(),
195+
task.swap_unwrap(),
179196
f);
180197

198+
let mut rng = rng();
199+
let run_now: bool = Rand::rand(&mut rng);
200+
181201
if run_now {
182202
do sched.switch_running_tasks_and_then(task) |sched, task| {
183203
sched.enqueue_task(task);
@@ -206,7 +226,7 @@ pub fn spawntask_try(f: ~fn()) -> Result<(), ()> {
206226
do sched.deschedule_running_task_and_then() |sched, old_task| {
207227
let old_task = Cell(old_task);
208228
let f = f.take();
209-
let new_task = ~do Coroutine::new(&mut sched.stack_pool) {
229+
let new_task = ~do Coroutine::new_root(&mut sched.stack_pool) {
210230
do (|| {
211231
(f.take())()
212232
}).finally {
@@ -229,11 +249,17 @@ pub fn spawntask_try(f: ~fn()) -> Result<(), ()> {
229249
pub fn spawntask_thread(f: ~fn()) -> Thread {
230250
use rt::sched::*;
231251

252+
let mut task = None;
253+
do Local::borrow::<Task>() |running_task| {
254+
task = Some(~running_task.new_child_without_unwinding());
255+
}
256+
257+
let task = Cell(task.swap_unwrap());
232258
let f = Cell(f);
233259
let thread = do Thread::start {
234260
let mut sched = ~new_test_uv_sched();
235261
let task = ~Coroutine::with_task(&mut sched.stack_pool,
236-
~Task::without_unwinding(),
262+
task.take(),
237263
f.take());
238264
sched.enqueue_task(task);
239265
sched.run();

branches/snap-stage3/src/libstd/task/spawn.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ use uint;
9191
use util;
9292
use unstable::sync::{Exclusive, exclusive};
9393
use rt::local::Local;
94+
use rt::task::Task;
9495

9596
#[cfg(test)] use task::default_task_opts;
9697

@@ -576,8 +577,14 @@ pub fn spawn_raw(opts: TaskOpts, f: ~fn()) {
576577
fn spawn_raw_newsched(_opts: TaskOpts, f: ~fn()) {
577578
use rt::sched::*;
578579

580+
let mut task = None;
581+
do Local::borrow::<Task>() |running_task| {
582+
task = Some(~running_task.new_child_without_unwinding());
583+
}
584+
579585
let mut sched = Local::take::<Scheduler>();
580-
let task = ~Coroutine::new(&mut sched.stack_pool, f);
586+
let task = ~Coroutine::with_task(&mut sched.stack_pool,
587+
task.swap_unwrap(), f);
581588
sched.schedule_new_task(task);
582589
}
583590

0 commit comments

Comments
 (0)