Skip to content

Commit b81f5c5

Browse files
committed
small cleanups in task/spawn.rs
1 parent dd40636 commit b81f5c5

File tree

1 file changed

+32
-45
lines changed

1 file changed

+32
-45
lines changed

src/libstd/task/spawn.rs

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,7 @@ fn taskgroup_key() -> local_data::Key<@@mut Taskgroup> {
446446
// Transitionary.
447447
struct RuntimeGlue;
448448
impl RuntimeGlue {
449-
fn kill_task(handle: KillHandle) {
450-
let mut handle = handle;
449+
fn kill_task(mut handle: KillHandle) {
451450
do handle.kill().map_move |killed_task| {
452451
let killed_task = Cell::new(killed_task);
453452
do Local::borrow::<Scheduler, ()> |sched| {
@@ -457,44 +456,38 @@ impl RuntimeGlue {
457456
}
458457

459458
fn with_task_handle_and_failing(blk: &fn(&KillHandle, bool)) {
460-
if in_green_task_context() {
461-
unsafe {
462-
// Can't use safe borrow, because the taskgroup destructor needs to
463-
// access the scheduler again to send kill signals to other tasks.
464-
let me = Local::unsafe_borrow::<Task>();
465-
blk((*me).death.kill_handle.get_ref(), (*me).unwinder.unwinding)
466-
}
467-
} else {
468-
rtabort!("task dying in bad context")
459+
rtassert!(in_green_task_context());
460+
unsafe {
461+
// Can't use safe borrow, because the taskgroup destructor needs to
462+
// access the scheduler again to send kill signals to other tasks.
463+
let me = Local::unsafe_borrow::<Task>();
464+
blk((*me).death.kill_handle.get_ref(), (*me).unwinder.unwinding)
469465
}
470466
}
471467

472468
fn with_my_taskgroup<U>(blk: &fn(&Taskgroup) -> U) -> U {
473-
if in_green_task_context() {
474-
unsafe {
475-
// Can't use safe borrow, because creating new hashmaps for the
476-
// tasksets requires an rng, which needs to borrow the sched.
477-
let me = Local::unsafe_borrow::<Task>();
478-
blk(match (*me).taskgroup {
479-
None => {
480-
// First task in its (unlinked/unsupervised) taskgroup.
481-
// Lazily initialize.
482-
let mut members = TaskSet::new();
483-
let my_handle = (*me).death.kill_handle.get_ref().clone();
484-
members.insert(my_handle);
485-
let tasks = Exclusive::new(Some(TaskGroupData {
486-
members: members,
487-
descendants: TaskSet::new(),
488-
}));
489-
let group = Taskgroup(tasks, AncestorList(None), None);
490-
(*me).taskgroup = Some(group);
491-
(*me).taskgroup.get_ref()
492-
}
493-
Some(ref group) => group,
494-
})
495-
}
496-
} else {
497-
rtabort!("spawning in bad context")
469+
rtassert!(in_green_task_context());
470+
unsafe {
471+
// Can't use safe borrow, because creating new hashmaps for the
472+
// tasksets requires an rng, which needs to borrow the sched.
473+
let me = Local::unsafe_borrow::<Task>();
474+
blk(match (*me).taskgroup {
475+
None => {
476+
// First task in its (unlinked/unsupervised) taskgroup.
477+
// Lazily initialize.
478+
let mut members = TaskSet::new();
479+
let my_handle = (*me).death.kill_handle.get_ref().clone();
480+
members.insert(my_handle);
481+
let tasks = Exclusive::new(Some(TaskGroupData {
482+
members: members,
483+
descendants: TaskSet::new(),
484+
}));
485+
let group = Taskgroup(tasks, AncestorList(None), None);
486+
(*me).taskgroup = Some(group);
487+
(*me).taskgroup.get_ref()
488+
}
489+
Some(ref group) => group,
490+
})
498491
}
499492
}
500493
}
@@ -567,17 +560,11 @@ fn enlist_many(child: &KillHandle, child_arc: &TaskGroupArc,
567560
result
568561
}
569562

570-
pub fn spawn_raw(opts: TaskOpts, f: ~fn()) {
571-
if in_green_task_context() {
572-
spawn_raw_newsched(opts, f)
573-
} else {
574-
fail!("can't spawn from this context")
575-
}
576-
}
577-
578-
fn spawn_raw_newsched(mut opts: TaskOpts, f: ~fn()) {
563+
pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) {
579564
use rt::sched::*;
580565

566+
rtassert!(in_green_task_context());
567+
581568
let child_data = Cell::new(gen_child_taskgroup(opts.linked, opts.supervised));
582569
let indestructible = opts.indestructible;
583570

0 commit comments

Comments
 (0)