Skip to content

Remove the functions get and clone from ARC, replace them with the corresponding methods #6723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions src/libextra/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub impl<'self> Condvar<'self> {
****************************************************************************/

/// An atomically reference counted wrapper for shared immutable state.
struct ARC<T> { x: UnsafeAtomicRcBox<T> }
pub struct ARC<T> { x: UnsafeAtomicRcBox<T> }

/// Create an atomically reference counted wrapper.
pub fn ARC<T:Const + Owned>(data: T) -> ARC<T> {
Expand All @@ -118,29 +118,22 @@ pub fn ARC<T:Const + Owned>(data: T) -> ARC<T> {
* Access the underlying data in an atomically reference counted
* wrapper.
*/
pub fn get<'a, T:Const + Owned>(rc: &'a ARC<T>) -> &'a T {
rc.get()
}

impl<T:Const+Owned> ARC<T> {
pub fn get<'a>(&'a self) -> &'a T {
pub impl<T:Const+Owned> ARC<T> {
fn get<'a>(&'a self) -> &'a T {
unsafe { &*self.x.get_immut() }
}
}

/**
* Duplicate an atomically reference counted wrapper.
*
* The resulting two `arc` objects will point to the same underlying data
* object. However, one of the `arc` objects can be sent to another task,
* allowing them to share the underlying data.
*/
pub fn clone<T:Const + Owned>(rc: &ARC<T>) -> ARC<T> {
ARC { x: rc.x.clone() }
}

impl<T:Const + Owned> Clone for ARC<T> {
fn clone(&self) -> ARC<T> {
clone(self)
ARC { x: self.x.clone() }
}
}

Expand Down Expand Up @@ -512,34 +505,31 @@ pub impl<'self, T:Const + Owned> RWReadMode<'self, T> {
#[cfg(test)]
mod tests {
use core::prelude::*;

use core::cell::Cell;
use arc::*;
use arc;

use core::cell::Cell;
use core::task;

#[test]
fn manually_share_arc() {
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let arc_v = arc::ARC(v);
let arc_v = ARC(v);

let (p, c) = comm::stream();

do task::spawn() || {
let p = comm::PortSet::new();
c.send(p.chan());

let arc_v = p.recv();
let arc_v : ARC<~[int]> = p.recv();

let v = copy *arc::get::<~[int]>(&arc_v);
let v = copy (*arc_v.get());
assert_eq!(v[3], 4);
};

let c = p.recv();
c.send(arc::clone(&arc_v));
c.send(arc_v.clone());

assert_eq!((*arc::get(&arc_v))[2], 3);
assert_eq!(arc_v.get()[2], 3);
assert_eq!(arc_v.get()[4], 5);

info!(arc_v);
Expand Down
14 changes: 7 additions & 7 deletions src/test/bench/graph500-bfs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// xfail-pretty

// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -234,7 +234,7 @@ fn pbfs(graph: &arc::ARC<graph>, key: node_id) -> bfs_result {
black(node_id)
};

let graph_vec = arc::get(graph); // FIXME #3387 requires this temp
let graph_vec = graph.get(); // FIXME #3387 requires this temp
let mut colors = do vec::from_fn(graph_vec.len()) |i| {
if i as node_id == key {
gray(key)
Expand Down Expand Up @@ -266,13 +266,13 @@ fn pbfs(graph: &arc::ARC<graph>, key: node_id) -> bfs_result {

let color = arc::ARC(colors);

let color_vec = arc::get(&color); // FIXME #3387 requires this temp
let color_vec = color.get(); // FIXME #3387 requires this temp
colors = do par::mapi(*color_vec) {
let colors = arc::clone(&color);
let graph = arc::clone(graph);
let colors = color.clone();
let graph = graph.clone();
let result: ~fn(x: uint, y: &color) -> color = |i, c| {
let colors = arc::get(&colors);
let graph = arc::get(&graph);
let colors = colors.get();
let graph = graph.get();
match *c {
white => {
let i = i as node_id;
Expand Down
6 changes: 3 additions & 3 deletions src/test/compile-fail/no-capture-arc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -18,11 +18,11 @@ fn main() {
let arc_v = arc::ARC(v);

do task::spawn() {
let v = *arc::get(&arc_v);
let v = arc_v.get();
assert_eq!(v[3], 4);
};

assert_eq!((*arc::get(&arc_v))[2], 3);
assert_eq!((arc_v.get())[2], 3);

info!(arc_v);
}
6 changes: 3 additions & 3 deletions src/test/compile-fail/no-reuse-move-arc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -16,11 +16,11 @@ fn main() {
let arc_v = arc::ARC(v);

do task::spawn() { //~ NOTE `arc_v` moved into closure environment here
let v = *arc::get(&arc_v);
let v = arc_v.get();
assert_eq!(v[3], 4);
};

assert!((*arc::get(&arc_v))[2] == 3); //~ ERROR use of moved value: `arc_v`
assert_eq!((arc_v.get())[2], 3); //~ ERROR use of moved value: `arc_v`

info!(arc_v);
}