20
20
21
21
#![ allow( dead_code) ]
22
22
23
+ use alloc:: arc:: Arc ;
23
24
use libc:: c_void;
24
25
use std:: mem;
25
26
use std:: rt:: task:: BlockedTask ;
26
- use std:: sync:: arc:: UnsafeArc ;
27
27
use std:: unstable:: mutex:: NativeMutex ;
28
28
use mpsc = std:: sync:: mpsc_queue;
29
29
@@ -46,20 +46,20 @@ struct State {
46
46
/// This structure is intended to be stored next to the event loop, and it is
47
47
/// used to create new `Queue` structures.
48
48
pub struct QueuePool {
49
- queue : UnsafeArc < State > ,
49
+ queue : Arc < State > ,
50
50
refcnt : uint ,
51
51
}
52
52
53
53
/// This type is used to send messages back to the original event loop.
54
54
pub struct Queue {
55
- queue : UnsafeArc < State > ,
55
+ queue : Arc < State > ,
56
56
}
57
57
58
58
extern fn async_cb ( handle : * uvll:: uv_async_t ) {
59
59
let pool: & mut QueuePool = unsafe {
60
60
mem:: transmute ( uvll:: get_data_for_uv_handle ( handle) )
61
61
} ;
62
- let state: & mut State = unsafe { mem :: transmute ( pool. queue . get ( ) ) } ;
62
+ let state: & State = & * pool. queue ;
63
63
64
64
// Remember that there is no guarantee about how many times an async
65
65
// callback is called with relation to the number of sends, so process the
@@ -109,7 +109,7 @@ extern fn async_cb(handle: *uvll::uv_async_t) {
109
109
impl QueuePool {
110
110
pub fn new ( loop_ : & mut Loop ) -> Box < QueuePool > {
111
111
let handle = UvHandle :: alloc ( None :: < AsyncWatcher > , uvll:: UV_ASYNC ) ;
112
- let state = UnsafeArc :: new ( State {
112
+ let state = Arc :: new ( State {
113
113
handle : handle,
114
114
lock : unsafe { NativeMutex :: new ( ) } ,
115
115
queue : mpsc:: Queue :: new ( ) ,
@@ -132,24 +132,20 @@ impl QueuePool {
132
132
pub fn queue ( & mut self ) -> Queue {
133
133
unsafe {
134
134
if self . refcnt == 0 {
135
- uvll:: uv_ref ( ( * self . queue . get ( ) ) . handle ) ;
135
+ uvll:: uv_ref ( self . queue . handle ) ;
136
136
}
137
137
self . refcnt += 1 ;
138
138
}
139
139
Queue { queue : self . queue . clone ( ) }
140
140
}
141
141
142
- pub fn handle ( & self ) -> * uvll:: uv_async_t {
143
- unsafe { ( * self . queue . get ( ) ) . handle }
144
- }
142
+ pub fn handle ( & self ) -> * uvll:: uv_async_t { self . queue . handle }
145
143
}
146
144
147
145
impl Queue {
148
146
pub fn push ( & mut self , task : BlockedTask ) {
149
- unsafe {
150
- ( * self . queue . get ( ) ) . queue . push ( Task ( task) ) ;
151
- uvll:: uv_async_send ( ( * self . queue . get ( ) ) . handle ) ;
152
- }
147
+ self . queue . queue . push ( Task ( task) ) ;
148
+ unsafe { uvll:: uv_async_send ( self . queue . handle ) ; }
153
149
}
154
150
}
155
151
@@ -160,9 +156,7 @@ impl Clone for Queue {
160
156
// that the count is at least one (because we have a queue right here),
161
157
// and if the queue is dropped later on it'll see the increment for the
162
158
// decrement anyway.
163
- unsafe {
164
- ( * self . queue . get ( ) ) . queue . push ( Increment ) ;
165
- }
159
+ self . queue . queue . push ( Increment ) ;
166
160
Queue { queue : self . queue . clone ( ) }
167
161
}
168
162
}
@@ -172,10 +166,9 @@ impl Drop for Queue {
172
166
// See the comments in the async_cb function for why there is a lock
173
167
// that is acquired only on a drop.
174
168
unsafe {
175
- let state = self . queue . get ( ) ;
176
- let _l = ( * state) . lock . lock ( ) ;
177
- ( * state) . queue . push ( Decrement ) ;
178
- uvll:: uv_async_send ( ( * state) . handle ) ;
169
+ let _l = self . queue . lock . lock ( ) ;
170
+ self . queue . queue . push ( Decrement ) ;
171
+ uvll:: uv_async_send ( self . queue . handle ) ;
179
172
}
180
173
}
181
174
}
0 commit comments