20
20
//! can be created in the future and there must be no active timers at that
21
21
//! time.
22
22
23
- #![ macro_escape]
24
-
25
23
use prelude:: * ;
26
24
27
25
use cell:: UnsafeCell ;
@@ -70,17 +68,6 @@ struct RaceBox(helper_signal::signal);
70
68
unsafe impl Send for RaceBox { }
71
69
unsafe impl Sync for RaceBox { }
72
70
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
-
84
71
impl < M : Send > Helper < M > {
85
72
/// Lazily boots a helper thread, becoming a no-op if the helper has already
86
73
/// been spawned.
@@ -97,7 +84,7 @@ impl<M: Send> Helper<M> {
97
84
{
98
85
unsafe {
99
86
let _guard = self . lock . lock ( ) . unwrap ( ) ;
100
- if * self . chan . get ( ) as uint == 0 {
87
+ if ! * self . initialized . get ( ) {
101
88
let ( tx, rx) = channel ( ) ;
102
89
* self . chan . get ( ) = mem:: transmute ( box tx) ;
103
90
let ( receive, send) = helper_signal:: new ( ) ;
@@ -106,17 +93,15 @@ impl<M: Send> Helper<M> {
106
93
let receive = RaceBox ( receive) ;
107
94
108
95
let t = f ( ) ;
109
- Thread :: spawn ( move || {
96
+ Thread :: spawn ( move |: | {
110
97
helper ( receive. 0 , rx, t) ;
111
98
let _g = self . lock . lock ( ) . unwrap ( ) ;
112
99
* self . shutdown . get ( ) = true ;
113
100
self . cond . notify_one ( )
114
101
} ) . detach ( ) ;
115
102
116
- rt:: at_exit ( move | | { self . shutdown ( ) } ) ;
103
+ rt:: at_exit ( move | : | { self . shutdown ( ) } ) ;
117
104
* self . initialized . get ( ) = true ;
118
- } else if * self . chan . get ( ) as uint == 1 {
119
- panic ! ( "cannot continue usage after shutdown" ) ;
120
105
}
121
106
}
122
107
}
@@ -131,9 +116,7 @@ impl<M: Send> Helper<M> {
131
116
// Must send and *then* signal to ensure that the child receives the
132
117
// message. Otherwise it could wake up and go to sleep before we
133
118
// 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( ) ) ;
137
120
( * * self . chan . get ( ) ) . send ( msg) ;
138
121
helper_signal:: signal ( * self . signal . get ( ) as helper_signal:: signal ) ;
139
122
}
@@ -146,13 +129,9 @@ impl<M: Send> Helper<M> {
146
129
// returns.
147
130
let mut guard = self . lock . lock ( ) . unwrap ( ) ;
148
131
149
- let ptr = * self . chan . get ( ) ;
150
- if ptr as uint == 1 {
151
- panic ! ( "cannot continue usage after shutdown" ) ;
152
- }
153
132
// Close the channel by destroying it
154
133
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 > ;
156
135
drop ( chan) ;
157
136
helper_signal:: signal ( * self . signal . get ( ) as helper_signal:: signal ) ;
158
137
0 commit comments