From fa8102ab4afc4deba80344f4a2fdb5861cbe394f Mon Sep 17 00:00:00 2001 From: Ben Blum Date: Mon, 22 Jul 2013 20:14:15 -0400 Subject: Unkillable is not unsafe. Close #7832. --- src/libstd/task/mod.rs | 44 +++++++++++++++++++++++--------------------- src/libstd/task/spawn.rs | 2 +- 2 files changed, 24 insertions(+), 22 deletions(-) (limited to 'src/libstd/task') diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index df927cb6a7a..c26349b220d 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -618,32 +618,34 @@ pub fn get_scheduler() -> Scheduler { * } * ~~~ */ -pub unsafe fn unkillable(f: &fn() -> U) -> U { +pub fn unkillable(f: &fn() -> U) -> U { use rt::task::Task; - match context() { - OldTaskContext => { - let t = rt::rust_get_task(); - do (|| { - rt::rust_task_inhibit_kill(t); - f() - }).finally { - rt::rust_task_allow_kill(t); + unsafe { + match context() { + OldTaskContext => { + let t = rt::rust_get_task(); + do (|| { + rt::rust_task_inhibit_kill(t); + f() + }).finally { + rt::rust_task_allow_kill(t); + } } - } - TaskContext => { - // The inhibits/allows might fail and need to borrow the task. - let t = Local::unsafe_borrow::(); - do (|| { - (*t).death.inhibit_kill((*t).unwinder.unwinding); - f() - }).finally { - (*t).death.allow_kill((*t).unwinder.unwinding); + TaskContext => { + // The inhibits/allows might fail and need to borrow the task. + let t = Local::unsafe_borrow::(); + do (|| { + (*t).death.inhibit_kill((*t).unwinder.unwinding); + f() + }).finally { + (*t).death.allow_kill((*t).unwinder.unwinding); + } } + // FIXME(#3095): This should be an rtabort as soon as the scheduler + // no longer uses a workqueue implemented with an Exclusive. + _ => f() } - // FIXME(#3095): This should be an rtabort as soon as the scheduler - // no longer uses a workqueue implemented with an Exclusive. - _ => f() } } diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index baebda496dc..749db307012 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -694,7 +694,7 @@ fn spawn_raw_newsched(mut opts: TaskOpts, f: ~fn()) { // Should be run after the local-borrowed task is returned. if enlist_success { if indestructible { - unsafe { do unkillable { f() } } + do unkillable { f() } } else { f() } -- cgit 1.4.1-3-g733a5