@@ -42,6 +42,7 @@ use result;
42
42
use task:: rt:: { task_id, sched_id, rust_task} ;
43
43
use util;
44
44
use util:: replace;
45
+ use unstable:: finally:: Finally ;
45
46
46
47
#[ cfg( test) ] use comm:: SharedChan ;
47
48
@@ -565,51 +566,27 @@ pub fn get_scheduler() -> Scheduler {
565
566
* ~~~
566
567
*/
567
568
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
-
583
569
unsafe {
584
570
let t = rt::rust_get_task();
585
- let _allow_failure = AllowFailure(t);
586
571
rt::rust_task_inhibit_kill(t);
587
- f()
572
+ do (|| {
573
+ f()
574
+ }).finally {
575
+ rt::rust_task_allow_kill(t);
576
+ }
588
577
}
589
578
}
590
579
591
580
/// The inverse of unkillable. Only ever to be used nested in unkillable().
592
581
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
-
608
582
unsafe {
609
583
let t = rt::rust_get_task();
610
- let _allow_failure = DisallowFailure(t);
611
584
rt::rust_task_allow_kill(t);
612
- f()
585
+ do (|| {
586
+ f()
587
+ }).finally {
588
+ rt::rust_task_inhibit_kill(t);
589
+ }
613
590
}
614
591
}
615
592
@@ -618,28 +595,16 @@ pub unsafe fn rekillable<U>(f: &fn() -> U) -> U {
618
595
* For use with exclusive ARCs, which use pthread mutexes directly.
619
596
*/
620
597
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
-
637
598
unsafe {
638
599
let t = rt::rust_get_task();
639
- let _interrupts = DeferInterrupts(t);
640
600
rt::rust_task_inhibit_kill(t);
641
601
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
+ }
643
608
}
644
609
}
645
610
0 commit comments