Skip to content

Commit 80b6bbd

Browse files
committed
auto merge of #5789 : brson/rust/drop, r=graydon
2 parents ec3cfae + 2e907a3 commit 80b6bbd

File tree

2 files changed

+23
-69
lines changed

2 files changed

+23
-69
lines changed

src/libcore/task/mod.rs

+17-52
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

@@ -565,51 +566,27 @@ pub fn get_scheduler() -> Scheduler {
565566
* ~~~
566567
*/
567568
pub unsafe fn unkillable<U>(f: &fn() -> U) -> U {
568-
struct AllowFailure {
569-
t: *rust_task,
570-
drop {
571-
unsafe {
572-
rt::rust_task_allow_kill(self.t);
573-
}
574-
}
575-
}
576-
577-
fn AllowFailure(t: *rust_task) -> AllowFailure{
578-
AllowFailure {
579-
t: t
580-
}
581-
}
582-
583569
unsafe {
584570
let t = rt::rust_get_task();
585-
let _allow_failure = AllowFailure(t);
586571
rt::rust_task_inhibit_kill(t);
587-
f()
572+
do (|| {
573+
f()
574+
}).finally {
575+
rt::rust_task_allow_kill(t);
576+
}
588577
}
589578
}
590579
591580
/// The inverse of unkillable. Only ever to be used nested in unkillable().
592581
pub unsafe fn rekillable<U>(f: &fn() -> U) -> U {
593-
struct DisallowFailure {
594-
t: *rust_task,
595-
drop {
596-
unsafe {
597-
rt::rust_task_inhibit_kill(self.t);
598-
}
599-
}
600-
}
601-
602-
fn DisallowFailure(t: *rust_task) -> DisallowFailure {
603-
DisallowFailure {
604-
t: t
605-
}
606-
}
607-
608582
unsafe {
609583
let t = rt::rust_get_task();
610-
let _allow_failure = DisallowFailure(t);
611584
rt::rust_task_allow_kill(t);
612-
f()
585+
do (|| {
586+
f()
587+
}).finally {
588+
rt::rust_task_inhibit_kill(t);
589+
}
613590
}
614591
}
615592
@@ -618,28 +595,16 @@ pub unsafe fn rekillable<U>(f: &fn() -> U) -> U {
618595
* For use with exclusive ARCs, which use pthread mutexes directly.
619596
*/
620597
pub unsafe fn atomically<U>(f: &fn() -> U) -> U {
621-
struct DeferInterrupts {
622-
t: *rust_task,
623-
drop {
624-
unsafe {
625-
rt::rust_task_allow_yield(self.t);
626-
rt::rust_task_allow_kill(self.t);
627-
}
628-
}
629-
}
630-
631-
fn DeferInterrupts(t: *rust_task) -> DeferInterrupts {
632-
DeferInterrupts {
633-
t: t
634-
}
635-
}
636-
637598
unsafe {
638599
let t = rt::rust_get_task();
639-
let _interrupts = DeferInterrupts(t);
640600
rt::rust_task_inhibit_kill(t);
641601
rt::rust_task_inhibit_yield(t);
642-
f()
602+
do (|| {
603+
f()
604+
}).finally {
605+
rt::rust_task_allow_yield(t);
606+
rt::rust_task_allow_kill(t);
607+
}
643608
}
644609
}
645610

src/libcore/unstable.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use comm::{GenericChan, GenericPort};
1616
use prelude::*;
1717
use task;
1818
use task::atomically;
19+
use self::finally::Finally;
1920

2021
#[path = "unstable/at_exit.rs"]
2122
pub mod at_exit;
@@ -229,25 +230,13 @@ fn LittleLock() -> LittleLock {
229230
pub impl LittleLock {
230231
#[inline(always)]
231232
unsafe fn lock<T>(&self, f: &fn() -> T) -> T {
232-
struct Unlock {
233-
l: rust_little_lock,
234-
drop {
235-
unsafe {
236-
rustrt::rust_unlock_little_lock(self.l);
237-
}
238-
}
239-
}
240-
241-
fn Unlock(l: rust_little_lock) -> Unlock {
242-
Unlock {
243-
l: l
244-
}
245-
}
246-
247233
do atomically {
248234
rustrt::rust_lock_little_lock(self.l);
249-
let _r = Unlock(self.l);
250-
f()
235+
do (|| {
236+
f()
237+
}).finally {
238+
rustrt::rust_unlock_little_lock(self.l);
239+
}
251240
}
252241
}
253242
}

0 commit comments

Comments
 (0)