green: Remove usage of UnsafeArc
This commit is contained in:
parent
5e10d373b5
commit
05a453edb3
@ -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(());
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user