Revert "Moved arc to libstd and added an arc that allows shared mutable state through mutual exclusion."

This reverts commit 015527b0ce.
This commit is contained in:
Tim Chevalier 2012-06-16 15:21:08 -07:00
parent 69447e9002
commit 0276a3376b
8 changed files with 16 additions and 74 deletions

View File

@ -39,7 +39,7 @@ export float, f32, f64;
export box, char, str, ptr, vec, bool;
export either, option, result, iter;
export libc, os, io, run, rand, sys, unsafe, logging;
export arc, comm, task, future;
export comm, task, future;
export extfmt;
export tuple;
export to_str;
@ -175,7 +175,6 @@ mod dvec_iter {
}
// Concurrency
mod arc;
mod comm;
mod task;
mod future;

View File

@ -7,7 +7,7 @@ export min_align_of;
export pref_align_of;
export refcount;
export log_str;
export create_lock, lock_and_signal, condition, methods;
export lock_and_signal, condition, methods;
enum type_desc = {
first_param: **libc::c_int,
@ -126,6 +126,8 @@ impl methods for condition {
#[cfg(test)]
mod tests {
use std;
import std::arc;
#[test]
fn size_of_basic() {

View File

@ -2,12 +2,9 @@
share immutable data between tasks."]
import comm::{port, chan, methods};
import sys::methods;
export arc, get, clone, shared_arc, get_arc;
export exclusive, methods;
#[abi = "cdecl"]
native mod rustrt {
#[rust_stack]
@ -19,12 +16,12 @@ native mod rustrt {
-> libc::intptr_t;
}
type arc_data<T> = {
type arc_data<T: const> = {
mut count: libc::intptr_t,
data: T
};
resource arc_destruct<T>(data: *libc::c_void) {
resource arc_destruct<T: const>(data: *libc::c_void) {
unsafe {
let data: ~arc_data<T> = unsafe::reinterpret_cast(data);
let new_count = rustrt::rust_atomic_decrement(&mut data.count);
@ -74,43 +71,6 @@ fn clone<T: const>(rc: &arc<T>) -> arc<T> {
arc_destruct(**rc)
}
// An arc over mutable data that is protected by a lock.
type ex_data<T> = {lock: sys::lock_and_signal, data: T};
type exclusive<T> = arc_destruct<ex_data<T>>;
fn exclusive<T>(-data: T) -> exclusive<T> {
let data = ~{mut count: 1, data: {lock: sys::create_lock(),
data: data}};
unsafe {
let ptr = unsafe::reinterpret_cast(data);
unsafe::forget(data);
arc_destruct(ptr)
}
}
impl methods<T> for exclusive<T> {
fn clone() -> exclusive<T> {
unsafe {
// this makes me nervous...
let ptr: ~arc_data<ex_data<T>> = unsafe::reinterpret_cast(*self);
rustrt::rust_atomic_increment(&mut ptr.count);
unsafe::forget(ptr);
}
arc_destruct(*self)
}
fn with<U>(f: fn(sys::condition, x: &T) -> U) -> U {
unsafe {
let ptr: ~arc_data<ex_data<T>> = unsafe::reinterpret_cast(*self);
let rec: &ex_data<T> = &(*ptr).data;
unsafe::forget(ptr);
rec.lock.lock_cond() {|c|
f(c, &rec.data)
}
}
}
}
// Convenience code for sharing arcs between tasks
type get_chan<T: const send> = chan<chan<arc<T>>>;
@ -155,7 +115,6 @@ fn get_arc<T: send const>(c: get_chan<T>) -> arc::arc<T> {
#[cfg(test)]
mod tests {
import comm::*;
import future::future;
#[test]
fn manually_share_arc() {
@ -201,31 +160,4 @@ mod tests {
assert p.recv() == ();
}
#[test]
fn exclusive_arc() {
let mut futures = [];
let num_tasks = 10u;
let count = 1000u;
let total = exclusive(~mut 0u);
for uint::range(0u, num_tasks) {|_i|
let total = total.clone();
futures += [future::spawn({||
for uint::range(0u, count) {|_i|
total.with {|_cond, count|
**count += 1u;
}
}
})];
};
for futures.each {|f| f.get() };
total.with {|_cond, total|
assert **total == num_tasks * count
};
}
}

View File

@ -19,7 +19,7 @@ export net, net_tcp;
export uv, uv_ll, uv_iotask, uv_global_loop;
export c_vec, util, timer;
export bitv, deque, fun_treemap, list, map, smallintmap, sort, treemap;
export rope, arena, par;
export rope, arena, arc, par;
export ebml, dbg, getopts, json, rand, sha1, term, time, prettyprint;
export test, tempfile, serialization;
export cmp;
@ -69,6 +69,7 @@ mod term;
mod time;
mod prettyprint;
mod arena;
mod arc;
mod par;
mod cmp;

View File

@ -10,6 +10,7 @@ import std::map;
import std::map::hashmap;
import std::deque;
import std::deque::t;
import std::arc;
import std::par;
import io::writer_util;
import comm::*;

View File

@ -1,5 +1,7 @@
// error-pattern: copying a noncopyable value
use std;
import std::arc;
import comm::*;
fn main() {

View File

@ -1,3 +1,5 @@
use std;
import std::arc;
import comm::*;
fn main() {

View File

@ -1,5 +1,8 @@
// error-pattern:explicit failure
use std;
import std::arc;
enum e<T: const> { e(arc::arc<T>) }
fn foo() -> e<int> {fail;}