std::rt: Tasks must have an unwinder. Simpler
This commit is contained in:
parent
fd148cd3e2
commit
90fbe38f00
5 changed files with 13 additions and 57 deletions
|
|
@ -25,7 +25,7 @@ pub struct Task {
|
|||
gc: GarbageCollector,
|
||||
storage: LocalStorage,
|
||||
logger: StdErrLogger,
|
||||
unwinder: Option<Unwinder>,
|
||||
unwinder: Unwinder,
|
||||
destroyed: bool
|
||||
}
|
||||
|
||||
|
|
@ -43,18 +43,7 @@ impl Task {
|
|||
gc: GarbageCollector,
|
||||
storage: LocalStorage(ptr::null(), None),
|
||||
logger: StdErrLogger,
|
||||
unwinder: Some(Unwinder { unwinding: false }),
|
||||
destroyed: false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_root_without_unwinding() -> Task {
|
||||
Task {
|
||||
heap: LocalHeap::new(),
|
||||
gc: GarbageCollector,
|
||||
storage: LocalStorage(ptr::null(), None),
|
||||
logger: StdErrLogger,
|
||||
unwinder: None,
|
||||
unwinder: Unwinder { unwinding: false },
|
||||
destroyed: false
|
||||
}
|
||||
}
|
||||
|
|
@ -65,18 +54,7 @@ impl Task {
|
|||
gc: GarbageCollector,
|
||||
storage: LocalStorage(ptr::null(), None),
|
||||
logger: StdErrLogger,
|
||||
unwinder: Some(Unwinder { unwinding: false }),
|
||||
destroyed: false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_child_without_unwinding(&mut self) -> Task {
|
||||
Task {
|
||||
heap: LocalHeap::new(),
|
||||
gc: GarbageCollector,
|
||||
storage: LocalStorage(ptr::null(), None),
|
||||
logger: StdErrLogger,
|
||||
unwinder: None,
|
||||
unwinder: Unwinder { unwinding: false },
|
||||
destroyed: false
|
||||
}
|
||||
}
|
||||
|
|
@ -88,16 +66,7 @@ impl Task {
|
|||
assert!(ptr::ref_eq(task, self));
|
||||
}
|
||||
|
||||
match self.unwinder {
|
||||
Some(ref mut unwinder) => {
|
||||
// If there's an unwinder then set up the catch block
|
||||
unwinder.try(f);
|
||||
}
|
||||
None => {
|
||||
// Otherwise, just run the body
|
||||
f()
|
||||
}
|
||||
}
|
||||
self.unwinder.try(f);
|
||||
self.destroy();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ pub fn run_in_newsched_task(f: ~fn()) {
|
|||
do run_in_bare_thread {
|
||||
let mut sched = ~new_test_uv_sched();
|
||||
let task = ~Coroutine::with_task(&mut sched.stack_pool,
|
||||
~Task::new_root_without_unwinding(),
|
||||
~Task::new_root(),
|
||||
f.take());
|
||||
sched.enqueue_task(task);
|
||||
sched.run();
|
||||
|
|
@ -134,7 +134,7 @@ pub fn spawntask(f: ~fn()) {
|
|||
|
||||
let mut task = None;
|
||||
do Local::borrow::<Task>() |running_task| {
|
||||
task = Some(~running_task.new_child_without_unwinding());
|
||||
task = Some(~running_task.new_child());
|
||||
}
|
||||
|
||||
let mut sched = Local::take::<Scheduler>();
|
||||
|
|
@ -150,7 +150,7 @@ pub fn spawntask_immediately(f: ~fn()) {
|
|||
|
||||
let mut task = None;
|
||||
do Local::borrow::<Task>() |running_task| {
|
||||
task = Some(~running_task.new_child_without_unwinding());
|
||||
task = Some(~running_task.new_child());
|
||||
}
|
||||
|
||||
let mut sched = Local::take::<Scheduler>();
|
||||
|
|
@ -168,7 +168,7 @@ pub fn spawntask_later(f: ~fn()) {
|
|||
|
||||
let mut task = None;
|
||||
do Local::borrow::<Task>() |running_task| {
|
||||
task = Some(~running_task.new_child_without_unwinding());
|
||||
task = Some(~running_task.new_child());
|
||||
}
|
||||
|
||||
let mut sched = Local::take::<Scheduler>();
|
||||
|
|
@ -187,7 +187,7 @@ pub fn spawntask_random(f: ~fn()) {
|
|||
|
||||
let mut task = None;
|
||||
do Local::borrow::<Task>() |running_task| {
|
||||
task = Some(~running_task.new_child_without_unwinding());
|
||||
task = Some(~running_task.new_child());
|
||||
}
|
||||
|
||||
let mut sched = Local::take::<Scheduler>();
|
||||
|
|
@ -251,7 +251,7 @@ pub fn spawntask_thread(f: ~fn()) -> Thread {
|
|||
|
||||
let mut task = None;
|
||||
do Local::borrow::<Task>() |running_task| {
|
||||
task = Some(~running_task.new_child_without_unwinding());
|
||||
task = Some(~running_task.new_child());
|
||||
}
|
||||
|
||||
let task = Cell(task.swap_unwrap());
|
||||
|
|
|
|||
|
|
@ -226,11 +226,7 @@ pub fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
|
|||
gc::cleanup_stack_for_failure();
|
||||
|
||||
let task = Local::unsafe_borrow::<Task>();
|
||||
let unwinder: &mut Option<Unwinder> = &mut (*task).unwinder;
|
||||
match *unwinder {
|
||||
Some(ref mut unwinder) => unwinder.begin_unwind(),
|
||||
None => abort!("failure without unwinder. aborting process")
|
||||
}
|
||||
(*task).unwinder.begin_unwind();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -515,16 +515,7 @@ pub fn failing() -> bool {
|
|||
_ => {
|
||||
let mut unwinding = false;
|
||||
do Local::borrow::<Task> |local| {
|
||||
unwinding = match local.unwinder {
|
||||
Some(unwinder) => {
|
||||
unwinder.unwinding
|
||||
}
|
||||
None => {
|
||||
// Because there is no unwinder we can't be unwinding.
|
||||
// (The process will abort on failure)
|
||||
false
|
||||
}
|
||||
}
|
||||
unwinding = local.unwinder.unwinding
|
||||
}
|
||||
return unwinding;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -579,7 +579,7 @@ fn spawn_raw_newsched(_opts: TaskOpts, f: ~fn()) {
|
|||
|
||||
let mut task = None;
|
||||
do Local::borrow::<Task>() |running_task| {
|
||||
task = Some(~running_task.new_child_without_unwinding());
|
||||
task = Some(~running_task.new_child());
|
||||
}
|
||||
|
||||
let mut sched = Local::take::<Scheduler>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue