2020//! can be created in the future and there must be no active timers at that
2121//! time.
2222
23- #![ macro_escape]
24-
2523use prelude:: * ;
2624
2725use cell:: UnsafeCell ;
@@ -70,17 +68,6 @@ struct RaceBox(helper_signal::signal);
7068unsafe impl Send for RaceBox { }
7169unsafe impl Sync for RaceBox { }
7270
73- macro_rules! helper_init { ( static $name: ident: Helper <$m: ty>) => (
74- static $name: Helper <$m> = Helper {
75- lock: :: sync:: MUTEX_INIT ,
76- cond: :: sync:: CONDVAR_INIT ,
77- chan: :: cell:: UnsafeCell { value: 0 as * mut Sender <$m> } ,
78- signal: :: cell:: UnsafeCell { value: 0 } ,
79- initialized: :: cell:: UnsafeCell { value: false } ,
80- shutdown: :: cell:: UnsafeCell { value: false } ,
81- } ;
82- ) }
83-
8471impl < M : Send > Helper < M > {
8572 /// Lazily boots a helper thread, becoming a no-op if the helper has already
8673 /// been spawned.
@@ -97,7 +84,7 @@ impl<M: Send> Helper<M> {
9784 {
9885 unsafe {
9986 let _guard = self . lock . lock ( ) . unwrap ( ) ;
100- if * self . chan . get ( ) as uint == 0 {
87+ if ! * self . initialized . get ( ) {
10188 let ( tx, rx) = channel ( ) ;
10289 * self . chan . get ( ) = mem:: transmute ( box tx) ;
10390 let ( receive, send) = helper_signal:: new ( ) ;
@@ -106,17 +93,15 @@ impl<M: Send> Helper<M> {
10693 let receive = RaceBox ( receive) ;
10794
10895 let t = f ( ) ;
109- Thread :: spawn ( move || {
96+ Thread :: spawn ( move |: | {
11097 helper ( receive. 0 , rx, t) ;
11198 let _g = self . lock . lock ( ) . unwrap ( ) ;
11299 * self . shutdown . get ( ) = true ;
113100 self . cond . notify_one ( )
114101 } ) . detach ( ) ;
115102
116- rt:: at_exit ( move | | { self . shutdown ( ) } ) ;
103+ rt:: at_exit ( move | : | { self . shutdown ( ) } ) ;
117104 * self . initialized . get ( ) = true ;
118- } else if * self . chan . get ( ) as uint == 1 {
119- panic ! ( "cannot continue usage after shutdown" ) ;
120105 }
121106 }
122107 }
@@ -131,9 +116,7 @@ impl<M: Send> Helper<M> {
131116 // Must send and *then* signal to ensure that the child receives the
132117 // message. Otherwise it could wake up and go to sleep before we
133118 // send the message.
134- assert ! ( * self . chan. get( ) as uint != 0 ) ;
135- assert ! ( * self . chan. get( ) as uint != 1 ,
136- "cannot continue usage after shutdown" ) ;
119+ assert ! ( !self . chan. get( ) . is_null( ) ) ;
137120 ( * * self . chan . get ( ) ) . send ( msg) ;
138121 helper_signal:: signal ( * self . signal . get ( ) as helper_signal:: signal ) ;
139122 }
@@ -146,13 +129,9 @@ impl<M: Send> Helper<M> {
146129 // returns.
147130 let mut guard = self . lock . lock ( ) . unwrap ( ) ;
148131
149- let ptr = * self . chan . get ( ) ;
150- if ptr as uint == 1 {
151- panic ! ( "cannot continue usage after shutdown" ) ;
152- }
153132 // Close the channel by destroying it
154133 let chan: Box < Sender < M > > = mem:: transmute ( * self . chan . get ( ) ) ;
155- * self . chan . get ( ) = 1 as * mut Sender < M > ;
134+ * self . chan . get ( ) = 0 as * mut Sender < M > ;
156135 drop ( chan) ;
157136 helper_signal:: signal ( * self . signal . get ( ) as helper_signal:: signal ) ;
158137
0 commit comments