Skip to content

Commit 05a453e

Browse files
committed
green: Remove usage of UnsafeArc
1 parent 5e10d37 commit 05a453e

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/libgreen/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@
214214
#[cfg(test)] extern crate rustuv;
215215
extern crate rand;
216216
extern crate libc;
217+
extern crate alloc;
217218

219+
use alloc::arc::Arc;
218220
use std::mem::replace;
219221
use std::os;
220222
use std::rt::rtio;
@@ -223,7 +225,6 @@ use std::rt;
223225
use std::sync::atomics::{SeqCst, AtomicUint, INIT_ATOMIC_UINT};
224226
use std::sync::deque;
225227
use std::task::TaskOpts;
226-
use std::sync::arc::UnsafeArc;
227228

228229
use sched::{Shutdown, Scheduler, SchedHandle, TaskFromFriend, NewNeighbor};
229230
use sleeper_list::SleeperList;
@@ -375,7 +376,7 @@ pub struct SchedPool {
375376
/// sending on a channel once the entire pool has been drained of all tasks.
376377
#[deriving(Clone)]
377378
struct TaskState {
378-
cnt: UnsafeArc<AtomicUint>,
379+
cnt: Arc<AtomicUint>,
379380
done: Sender<()>,
380381
}
381382

@@ -537,21 +538,21 @@ impl TaskState {
537538
fn new() -> (Receiver<()>, TaskState) {
538539
let (tx, rx) = channel();
539540
(rx, TaskState {
540-
cnt: UnsafeArc::new(AtomicUint::new(0)),
541+
cnt: Arc::new(AtomicUint::new(0)),
541542
done: tx,
542543
})
543544
}
544545

545546
fn increment(&mut self) {
546-
unsafe { (*self.cnt.get()).fetch_add(1, SeqCst); }
547+
self.cnt.fetch_add(1, SeqCst);
547548
}
548549

549550
fn active(&self) -> bool {
550-
unsafe { (*self.cnt.get()).load(SeqCst) != 0 }
551+
self.cnt.load(SeqCst) != 0
551552
}
552553

553554
fn decrement(&mut self) {
554-
let prev = unsafe { (*self.cnt.get()).fetch_sub(1, SeqCst) };
555+
let prev = self.cnt.fetch_sub(1, SeqCst);
555556
if prev == 1 {
556557
self.done.send(());
557558
}

src/libgreen/message_queue.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use alloc::arc::Arc;
1112
use mpsc = std::sync::mpsc_queue;
12-
use std::sync::arc::UnsafeArc;
1313

1414
pub enum PopResult<T> {
1515
Inconsistent,
@@ -18,29 +18,29 @@ pub enum PopResult<T> {
1818
}
1919

2020
pub fn queue<T: Send>() -> (Consumer<T>, Producer<T>) {
21-
let (a, b) = UnsafeArc::new2(mpsc::Queue::new());
22-
(Consumer { inner: a }, Producer { inner: b })
21+
let a = Arc::new(mpsc::Queue::new());
22+
(Consumer { inner: a.clone() }, Producer { inner: a })
2323
}
2424

2525
pub struct Producer<T> {
26-
inner: UnsafeArc<mpsc::Queue<T>>,
26+
inner: Arc<mpsc::Queue<T>>,
2727
}
2828

2929
pub struct Consumer<T> {
30-
inner: UnsafeArc<mpsc::Queue<T>>,
30+
inner: Arc<mpsc::Queue<T>>,
3131
}
3232

3333
impl<T: Send> Consumer<T> {
34-
pub fn pop(&mut self) -> PopResult<T> {
35-
match unsafe { (*self.inner.get()).pop() } {
34+
pub fn pop(&self) -> PopResult<T> {
35+
match self.inner.pop() {
3636
mpsc::Inconsistent => Inconsistent,
3737
mpsc::Empty => Empty,
3838
mpsc::Data(t) => Data(t),
3939
}
4040
}
4141

42-
pub fn casual_pop(&mut self) -> Option<T> {
43-
match unsafe { (*self.inner.get()).pop() } {
42+
pub fn casual_pop(&self) -> Option<T> {
43+
match self.inner.pop() {
4444
mpsc::Inconsistent => None,
4545
mpsc::Empty => None,
4646
mpsc::Data(t) => Some(t),
@@ -49,8 +49,8 @@ impl<T: Send> Consumer<T> {
4949
}
5050

5151
impl<T: Send> Producer<T> {
52-
pub fn push(&mut self, t: T) {
53-
unsafe { (*self.inner.get()).push(t); }
52+
pub fn push(&self, t: T) {
53+
self.inner.push(t);
5454
}
5555
}
5656

0 commit comments

Comments
 (0)