core: remove unnecessary unsafe blocks/functions

This commit is contained in:
Alex Crichton
2013-04-09 01:31:23 -04:00
parent 4bfa3c6663
commit d9595d1737
17 changed files with 227 additions and 243 deletions

View File

@@ -39,10 +39,9 @@ use result::Result;
use comm::{stream, Chan, GenericChan, GenericPort, Port};
use prelude::*;
use result;
use task::rt::{task_id, sched_id};
use task::rt::{task_id, sched_id, rust_task};
use util;
use util::replace;
use unstable::finally::Finally;
#[cfg(test)] use comm::SharedChan;
@@ -566,28 +565,48 @@ pub fn get_scheduler() -> Scheduler {
* ~~~
*/
pub unsafe fn unkillable<U>(f: &fn() -> U) -> U {
unsafe {
let t = rt::rust_get_task();
rt::rust_task_inhibit_kill(t);
do (|| {
f()
}).finally {
rt::rust_task_allow_kill(t);
struct AllowFailure {
t: *rust_task,
drop {
unsafe {
rt::rust_task_allow_kill(self.t);
}
}
}
fn AllowFailure(t: *rust_task) -> AllowFailure{
AllowFailure {
t: t
}
}
let t = rt::rust_get_task();
let _allow_failure = AllowFailure(t);
rt::rust_task_inhibit_kill(t);
f()
}
/// The inverse of unkillable. Only ever to be used nested in unkillable().
pub unsafe fn rekillable<U>(f: &fn() -> U) -> U {
unsafe {
let t = rt::rust_get_task();
rt::rust_task_allow_kill(t);
do (|| {
f()
}).finally {
rt::rust_task_inhibit_kill(t);
struct DisallowFailure {
t: *rust_task,
drop {
unsafe {
rt::rust_task_inhibit_kill(self.t);
}
}
}
fn DisallowFailure(t: *rust_task) -> DisallowFailure {
DisallowFailure {
t: t
}
}
let t = rt::rust_get_task();
let _allow_failure = DisallowFailure(t);
rt::rust_task_allow_kill(t);
f()
}
/**
@@ -595,17 +614,27 @@ pub unsafe fn rekillable<U>(f: &fn() -> U) -> U {
* For use with exclusive ARCs, which use pthread mutexes directly.
*/
pub unsafe fn atomically<U>(f: &fn() -> U) -> U {
unsafe {
let t = rt::rust_get_task();
rt::rust_task_inhibit_kill(t);
rt::rust_task_inhibit_yield(t);
do (|| {
f()
}).finally {
rt::rust_task_allow_yield(t);
rt::rust_task_allow_kill(t);
struct DeferInterrupts {
t: *rust_task,
drop {
unsafe {
rt::rust_task_allow_yield(self.t);
rt::rust_task_allow_kill(self.t);
}
}
}
fn DeferInterrupts(t: *rust_task) -> DeferInterrupts {
DeferInterrupts {
t: t
}
}
let t = rt::rust_get_task();
let _interrupts = DeferInterrupts(t);
rt::rust_task_inhibit_kill(t);
rt::rust_task_inhibit_yield(t);
f()
}
#[test] #[should_fail] #[ignore(cfg(windows))]