Skip to content

Commit c1fdace

Browse files
committed
core: Replace uses of 'drop' in task module with 'finally'. #5379
1 parent 3290110 commit c1fdace

File tree

1 file changed

+21
-56
lines changed

1 file changed

+21
-56
lines changed

src/libcore/task/mod.rs

+21-56
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use result;
4242
use task::rt::{task_id, sched_id, rust_task};
4343
use util;
4444
use util::replace;
45+
use unstable::finally::Finally;
4546

4647
#[cfg(test)] use comm::SharedChan;
4748

@@ -591,76 +592,40 @@ pub fn get_scheduler() -> Scheduler {
591592
* ~~~
592593
*/
593594
pub unsafe fn unkillable<U>(f: &fn() -> U) -> U {
594-
struct AllowFailure {
595-
t: *rust_task,
596-
drop {
597-
unsafe {
598-
rt::rust_task_allow_kill(self.t);
599-
}
600-
}
601-
}
602-
603-
fn AllowFailure(t: *rust_task) -> AllowFailure{
604-
AllowFailure {
605-
t: t
606-
}
607-
}
608-
609595
let t = rt::rust_get_task();
610-
let _allow_failure = AllowFailure(t);
611-
rt::rust_task_inhibit_kill(t);
612-
f()
596+
do (|| {
597+
rt::rust_task_inhibit_kill(t);
598+
f()
599+
}).finally {
600+
rt::rust_task_allow_kill(t);
601+
}
613602
}
614603
615604
/// The inverse of unkillable. Only ever to be used nested in unkillable().
616605
pub unsafe fn rekillable<U>(f: &fn() -> U) -> U {
617-
struct DisallowFailure {
618-
t: *rust_task,
619-
drop {
620-
unsafe {
621-
rt::rust_task_inhibit_kill(self.t);
622-
}
623-
}
624-
}
625-
626-
fn DisallowFailure(t: *rust_task) -> DisallowFailure {
627-
DisallowFailure {
628-
t: t
629-
}
630-
}
631-
632606
let t = rt::rust_get_task();
633-
let _allow_failure = DisallowFailure(t);
634-
rt::rust_task_allow_kill(t);
635-
f()
607+
do (|| {
608+
rt::rust_task_allow_kill(t);
609+
f()
610+
}).finally {
611+
rt::rust_task_inhibit_kill(t);
612+
}
636613
}
637614
638615
/**
639616
* A stronger version of unkillable that also inhibits scheduling operations.
640617
* For use with exclusive ARCs, which use pthread mutexes directly.
641618
*/
642619
pub unsafe fn atomically<U>(f: &fn() -> U) -> U {
643-
struct DeferInterrupts {
644-
t: *rust_task,
645-
drop {
646-
unsafe {
647-
rt::rust_task_allow_yield(self.t);
648-
rt::rust_task_allow_kill(self.t);
649-
}
650-
}
651-
}
652-
653-
fn DeferInterrupts(t: *rust_task) -> DeferInterrupts {
654-
DeferInterrupts {
655-
t: t
656-
}
657-
}
658-
659620
let t = rt::rust_get_task();
660-
let _interrupts = DeferInterrupts(t);
661-
rt::rust_task_inhibit_kill(t);
662-
rt::rust_task_inhibit_yield(t);
663-
f()
621+
do (|| {
622+
rt::rust_task_inhibit_kill(t);
623+
rt::rust_task_inhibit_yield(t);
624+
f()
625+
}).finally {
626+
rt::rust_task_allow_yield(t);
627+
rt::rust_task_allow_kill(t);
628+
}
664629
}
665630
666631
#[test] #[should_fail] #[ignore(cfg(windows))]

0 commit comments

Comments
 (0)