33
33
//! These tasks are not parallelized (they haven't been a bottleneck yet), and
34
34
//! both occur before the crate is rendered.
35
35
36
- use std:: cell:: Cell ;
37
36
use std:: comm:: { SharedPort , SharedChan } ;
38
37
use std:: comm;
39
38
use std:: fmt;
@@ -46,7 +45,6 @@ use std::io::File;
46
45
use std:: os;
47
46
use std:: str;
48
47
use std:: task;
49
- use std:: unstable:: finally:: Finally ;
50
48
use std:: vec;
51
49
52
50
use extra:: arc:: RWArc ;
@@ -642,6 +640,22 @@ impl<'self> Cache {
642
640
}
643
641
}
644
642
643
+ enum Progress {
644
+ JobNew ,
645
+ JobDone ,
646
+ }
647
+
648
+ /// A helper object to unconditionally send a value on a chanel.
649
+ struct ChannelGuard {
650
+ channel : SharedChan < Progress > ,
651
+ }
652
+
653
+ impl Drop for ChannelGuard {
654
+ fn drop ( & mut self ) {
655
+ self . channel . send ( JobDone )
656
+ }
657
+ }
658
+
645
659
impl Context {
646
660
/// Recurse in the directory structure and change the "root path" to make
647
661
/// sure it always points to the top (relatively)
@@ -674,8 +688,6 @@ impl Context {
674
688
Die ,
675
689
Process ( Context , clean:: Item ) ,
676
690
}
677
- enum Progress { JobNew , JobDone }
678
-
679
691
let workers = match os:: getenv ( "RUSTDOC_WORKERS" ) {
680
692
Some ( s) => {
681
693
match from_str :: < uint > ( s) {
@@ -725,16 +737,15 @@ impl Context {
725
737
match port. recv ( ) {
726
738
Process ( cx, item) => {
727
739
let mut cx = cx;
728
- let item = Cell :: new ( item) ;
729
- ( || {
730
- cx. item ( item. take ( ) , |cx, item| {
731
- prog_chan. send ( JobNew ) ;
732
- chan. send ( Process ( cx. clone ( ) , item) ) ;
733
- } )
734
- } ) . finally ( || {
735
- // If we fail, everything else should still get
736
- // completed
737
- prog_chan. send ( JobDone ) ;
740
+
741
+ // If we fail, everything else should still get
742
+ // completed.
743
+ let _guard = ChannelGuard {
744
+ channel : prog_chan. clone ( ) ,
745
+ } ;
746
+ cx. item ( item, |cx, item| {
747
+ prog_chan. send ( JobNew ) ;
748
+ chan. send ( Process ( cx. clone ( ) , item) ) ;
738
749
} )
739
750
}
740
751
Die => break ,
@@ -802,9 +813,9 @@ impl Context {
802
813
// recurse into the items of the module as well.
803
814
clean:: ModuleItem ( ..) => {
804
815
let name = item. name . get_ref ( ) . to_owned ( ) ;
805
- let item = Cell :: new ( item) ;
816
+ let mut item = Some ( item) ;
806
817
self . recurse ( name, |this| {
807
- let item = item. take ( ) ;
818
+ let item = item. take_unwrap ( ) ;
808
819
let dst = this. dst . join ( "index.html" ) ;
809
820
render ( File :: create ( & dst) . unwrap ( ) , this, & item, false ) ;
810
821
0 commit comments