3333//! These tasks are not parallelized (they haven't been a bottleneck yet), and
3434//! both occur before the crate is rendered.
3535
36- use std:: cell:: Cell ;
3736use std:: comm:: { SharedPort , SharedChan } ;
3837use std:: comm;
3938use std:: fmt;
@@ -46,7 +45,6 @@ use std::io::File;
4645use std:: os;
4746use std:: str;
4847use std:: task;
49- use std:: unstable:: finally:: Finally ;
5048use std:: vec;
5149
5250use extra:: arc:: RWArc ;
@@ -642,6 +640,22 @@ impl<'self> Cache {
642640 }
643641}
644642
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+
645659impl Context {
646660 /// Recurse in the directory structure and change the "root path" to make
647661 /// sure it always points to the top (relatively)
@@ -674,8 +688,6 @@ impl Context {
674688 Die ,
675689 Process ( Context , clean:: Item ) ,
676690 }
677- enum Progress { JobNew , JobDone }
678-
679691 let workers = match os:: getenv ( "RUSTDOC_WORKERS" ) {
680692 Some ( s) => {
681693 match from_str :: < uint > ( s) {
@@ -725,16 +737,15 @@ impl Context {
725737 match port. recv ( ) {
726738 Process ( cx, item) => {
727739 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) ) ;
738749 } )
739750 }
740751 Die => break ,
@@ -802,9 +813,9 @@ impl Context {
802813 // recurse into the items of the module as well.
803814 clean:: ModuleItem ( ..) => {
804815 let name = item. name . get_ref ( ) . to_owned ( ) ;
805- let item = Cell :: new ( item) ;
816+ let mut item = Some ( item) ;
806817 self . recurse ( name, |this| {
807- let item = item. take ( ) ;
818+ let item = item. take_unwrap ( ) ;
808819 let dst = this. dst . join ( "index.html" ) ;
809820 render ( File :: create ( & dst) . unwrap ( ) , this, & item, false ) ;
810821
0 commit comments