diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-05-19 18:08:44 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-05-19 18:12:18 -0700 |
| commit | 05a453edb3f97aab4c15efdeae238aaea21849a5 (patch) | |
| tree | e2e926df4bb12766ddb6b81f629b57a89464fa6a | |
| parent | 5e10d373b597192f101b52060c95adaa83c48663 (diff) | |
| download | rust-05a453edb3f97aab4c15efdeae238aaea21849a5.tar.gz rust-05a453edb3f97aab4c15efdeae238aaea21849a5.zip | |
green: Remove usage of UnsafeArc
| -rw-r--r-- | src/libgreen/lib.rs | 13 | ||||
| -rw-r--r-- | src/libgreen/message_queue.rs | 22 |
2 files changed, 18 insertions, 17 deletions
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<AtomicUint>, + cnt: Arc<AtomicUint>, 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<T> { Inconsistent, @@ -18,29 +18,29 @@ pub enum PopResult<T> { } pub fn queue<T: Send>() -> (Consumer<T>, Producer<T>) { - 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<T> { - inner: UnsafeArc<mpsc::Queue<T>>, + inner: Arc<mpsc::Queue<T>>, } pub struct Consumer<T> { - inner: UnsafeArc<mpsc::Queue<T>>, + inner: Arc<mpsc::Queue<T>>, } impl<T: Send> Consumer<T> { - pub fn pop(&mut self) -> PopResult<T> { - match unsafe { (*self.inner.get()).pop() } { + pub fn pop(&self) -> PopResult<T> { + match self.inner.pop() { mpsc::Inconsistent => Inconsistent, mpsc::Empty => Empty, mpsc::Data(t) => Data(t), } } - pub fn casual_pop(&mut self) -> Option<T> { - match unsafe { (*self.inner.get()).pop() } { + pub fn casual_pop(&self) -> Option<T> { + match self.inner.pop() { mpsc::Inconsistent => None, mpsc::Empty => None, mpsc::Data(t) => Some(t), @@ -49,8 +49,8 @@ impl<T: Send> Consumer<T> { } impl<T: Send> Producer<T> { - pub fn push(&mut self, t: T) { - unsafe { (*self.inner.get()).push(t); } + pub fn push(&self, t: T) { + self.inner.push(t); } } |
