diff --git a/src/libgreen/lib.rs b/src/libgreen/lib.rs index eec413635a5..53e2574df59 100644 --- a/src/libgreen/lib.rs +++ b/src/libgreen/lib.rs @@ -214,7 +214,9 @@ #[cfg(test)] extern crate rustuv; extern crate rand; extern crate libc; +extern crate alloc; +use alloc::arc::Arc; use std::mem::replace; use std::os; use std::rt::rtio; @@ -223,7 +225,6 @@ use std::rt; use std::sync::atomics::{SeqCst, AtomicUint, INIT_ATOMIC_UINT}; use std::sync::deque; use std::task::TaskOpts; -use std::sync::arc::UnsafeArc; use sched::{Shutdown, Scheduler, SchedHandle, TaskFromFriend, NewNeighbor}; use sleeper_list::SleeperList; @@ -375,7 +376,7 @@ pub struct SchedPool { /// sending on a channel once the entire pool has been drained of all tasks. #[deriving(Clone)] struct TaskState { - cnt: UnsafeArc, + cnt: Arc, done: Sender<()>, } @@ -537,21 +538,21 @@ impl TaskState { fn new() -> (Receiver<()>, TaskState) { let (tx, rx) = channel(); (rx, TaskState { - cnt: UnsafeArc::new(AtomicUint::new(0)), + cnt: Arc::new(AtomicUint::new(0)), done: tx, }) } fn increment(&mut self) { - unsafe { (*self.cnt.get()).fetch_add(1, SeqCst); } + self.cnt.fetch_add(1, SeqCst); } fn active(&self) -> bool { - unsafe { (*self.cnt.get()).load(SeqCst) != 0 } + self.cnt.load(SeqCst) != 0 } fn decrement(&mut self) { - let prev = unsafe { (*self.cnt.get()).fetch_sub(1, SeqCst) }; + let prev = self.cnt.fetch_sub(1, SeqCst); if prev == 1 { self.done.send(()); } diff --git a/src/libgreen/message_queue.rs b/src/libgreen/message_queue.rs index 50666b8c649..99dbf9c8919 100644 --- a/src/libgreen/message_queue.rs +++ b/src/libgreen/message_queue.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use alloc::arc::Arc; use mpsc = std::sync::mpsc_queue; -use std::sync::arc::UnsafeArc; pub enum PopResult { Inconsistent, @@ -18,29 +18,29 @@ pub enum PopResult { } pub fn queue() -> (Consumer, Producer) { - let (a, b) = UnsafeArc::new2(mpsc::Queue::new()); - (Consumer { inner: a }, Producer { inner: b }) + let a = Arc::new(mpsc::Queue::new()); + (Consumer { inner: a.clone() }, Producer { inner: a }) } pub struct Producer { - inner: UnsafeArc>, + inner: Arc>, } pub struct Consumer { - inner: UnsafeArc>, + inner: Arc>, } impl Consumer { - pub fn pop(&mut self) -> PopResult { - match unsafe { (*self.inner.get()).pop() } { + pub fn pop(&self) -> PopResult { + match self.inner.pop() { mpsc::Inconsistent => Inconsistent, mpsc::Empty => Empty, mpsc::Data(t) => Data(t), } } - pub fn casual_pop(&mut self) -> Option { - match unsafe { (*self.inner.get()).pop() } { + pub fn casual_pop(&self) -> Option { + match self.inner.pop() { mpsc::Inconsistent => None, mpsc::Empty => None, mpsc::Data(t) => Some(t), @@ -49,8 +49,8 @@ impl Consumer { } impl Producer { - pub fn push(&mut self, t: T) { - unsafe { (*self.inner.get()).push(t); } + pub fn push(&self, t: T) { + self.inner.push(t); } }