Skip to content

Commit 5e10d37

Browse files
committed
rustuv: Remove usage of UnsafeArc
1 parent 88b322c commit 5e10d37

File tree

4 files changed

+23
-27
lines changed

4 files changed

+23
-27
lines changed

src/librustuv/access.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
/// It is assumed that all invocations of this struct happen on the same thread
1515
/// (the uv event loop).
1616
17+
use alloc::arc::Arc;
1718
use std::mem;
1819
use std::rt::local::Local;
1920
use std::rt::task::{BlockedTask, Task};
20-
use std::sync::arc::UnsafeArc;
21+
use std::ty::Unsafe;
2122

2223
use homing::HomingMissile;
2324

2425
pub struct Access {
25-
inner: UnsafeArc<Inner>,
26+
inner: Arc<Unsafe<Inner>>,
2627
}
2728

2829
pub struct Guard<'a> {
@@ -39,11 +40,11 @@ struct Inner {
3940
impl Access {
4041
pub fn new() -> Access {
4142
Access {
42-
inner: UnsafeArc::new(Inner {
43+
inner: Arc::new(Unsafe::new(Inner {
4344
queue: vec![],
4445
held: false,
4546
closed: false,
46-
})
47+
}))
4748
}
4849
}
4950

src/librustuv/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ via `close` and `delete` methods.
4646
#[cfg(test)] extern crate green;
4747
#[cfg(test)] extern crate realrustuv = "rustuv";
4848
extern crate libc;
49+
extern crate alloc;
4950

5051
use libc::{c_int, c_void};
5152
use std::fmt;

src/librustuv/queue.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
2121
#![allow(dead_code)]
2222

23+
use alloc::arc::Arc;
2324
use libc::c_void;
2425
use std::mem;
2526
use std::rt::task::BlockedTask;
26-
use std::sync::arc::UnsafeArc;
2727
use std::unstable::mutex::NativeMutex;
2828
use mpsc = std::sync::mpsc_queue;
2929

@@ -46,20 +46,20 @@ struct State {
4646
/// This structure is intended to be stored next to the event loop, and it is
4747
/// used to create new `Queue` structures.
4848
pub struct QueuePool {
49-
queue: UnsafeArc<State>,
49+
queue: Arc<State>,
5050
refcnt: uint,
5151
}
5252

5353
/// This type is used to send messages back to the original event loop.
5454
pub struct Queue {
55-
queue: UnsafeArc<State>,
55+
queue: Arc<State>,
5656
}
5757

5858
extern fn async_cb(handle: *uvll::uv_async_t) {
5959
let pool: &mut QueuePool = unsafe {
6060
mem::transmute(uvll::get_data_for_uv_handle(handle))
6161
};
62-
let state: &mut State = unsafe { mem::transmute(pool.queue.get()) };
62+
let state: &State = &*pool.queue;
6363

6464
// Remember that there is no guarantee about how many times an async
6565
// 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) {
109109
impl QueuePool {
110110
pub fn new(loop_: &mut Loop) -> Box<QueuePool> {
111111
let handle = UvHandle::alloc(None::<AsyncWatcher>, uvll::UV_ASYNC);
112-
let state = UnsafeArc::new(State {
112+
let state = Arc::new(State {
113113
handle: handle,
114114
lock: unsafe {NativeMutex::new()},
115115
queue: mpsc::Queue::new(),
@@ -132,24 +132,20 @@ impl QueuePool {
132132
pub fn queue(&mut self) -> Queue {
133133
unsafe {
134134
if self.refcnt == 0 {
135-
uvll::uv_ref((*self.queue.get()).handle);
135+
uvll::uv_ref(self.queue.handle);
136136
}
137137
self.refcnt += 1;
138138
}
139139
Queue { queue: self.queue.clone() }
140140
}
141141

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 }
145143
}
146144

147145
impl Queue {
148146
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); }
153149
}
154150
}
155151

@@ -160,9 +156,7 @@ impl Clone for Queue {
160156
// that the count is at least one (because we have a queue right here),
161157
// and if the queue is dropped later on it'll see the increment for the
162158
// decrement anyway.
163-
unsafe {
164-
(*self.queue.get()).queue.push(Increment);
165-
}
159+
self.queue.queue.push(Increment);
166160
Queue { queue: self.queue.clone() }
167161
}
168162
}
@@ -172,10 +166,9 @@ impl Drop for Queue {
172166
// See the comments in the async_cb function for why there is a lock
173167
// that is acquired only on a drop.
174168
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);
179172
}
180173
}
181174
}

src/librustuv/rc.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@
1616
/// the same underlying uv object, hence Rc is not used and this simple counter
1717
/// should suffice.
1818
19-
use std::sync::arc::UnsafeArc;
19+
use alloc::arc::Arc;
20+
use std::ty::Unsafe;
2021

2122
pub struct Refcount {
22-
rc: UnsafeArc<uint>,
23+
rc: Arc<Unsafe<uint>>,
2324
}
2425

2526
impl Refcount {
2627
/// Creates a new refcount of 1
2728
pub fn new() -> Refcount {
28-
Refcount { rc: UnsafeArc::new(1) }
29+
Refcount { rc: Arc::new(Unsafe::new(1)) }
2930
}
3031

3132
fn increment(&self) {

0 commit comments

Comments
 (0)