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:
parent
69447e9002
commit
0276a3376b
8 changed files with 16 additions and 74 deletions
|
@ -39,7 +39,7 @@ export float, f32, f64;
|
||||||
export box, char, str, ptr, vec, bool;
|
export box, char, str, ptr, vec, bool;
|
||||||
export either, option, result, iter;
|
export either, option, result, iter;
|
||||||
export libc, os, io, run, rand, sys, unsafe, logging;
|
export libc, os, io, run, rand, sys, unsafe, logging;
|
||||||
export arc, comm, task, future;
|
export comm, task, future;
|
||||||
export extfmt;
|
export extfmt;
|
||||||
export tuple;
|
export tuple;
|
||||||
export to_str;
|
export to_str;
|
||||||
|
@ -175,7 +175,6 @@ mod dvec_iter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Concurrency
|
// Concurrency
|
||||||
mod arc;
|
|
||||||
mod comm;
|
mod comm;
|
||||||
mod task;
|
mod task;
|
||||||
mod future;
|
mod future;
|
||||||
|
|
|
@ -7,7 +7,7 @@ export min_align_of;
|
||||||
export pref_align_of;
|
export pref_align_of;
|
||||||
export refcount;
|
export refcount;
|
||||||
export log_str;
|
export log_str;
|
||||||
export create_lock, lock_and_signal, condition, methods;
|
export lock_and_signal, condition, methods;
|
||||||
|
|
||||||
enum type_desc = {
|
enum type_desc = {
|
||||||
first_param: **libc::c_int,
|
first_param: **libc::c_int,
|
||||||
|
@ -126,6 +126,8 @@ impl methods for condition {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std;
|
||||||
|
import std::arc;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn size_of_basic() {
|
fn size_of_basic() {
|
||||||
|
|
|
@ -2,12 +2,9 @@
|
||||||
share immutable data between tasks."]
|
share immutable data between tasks."]
|
||||||
|
|
||||||
import comm::{port, chan, methods};
|
import comm::{port, chan, methods};
|
||||||
import sys::methods;
|
|
||||||
|
|
||||||
export arc, get, clone, shared_arc, get_arc;
|
export arc, get, clone, shared_arc, get_arc;
|
||||||
|
|
||||||
export exclusive, methods;
|
|
||||||
|
|
||||||
#[abi = "cdecl"]
|
#[abi = "cdecl"]
|
||||||
native mod rustrt {
|
native mod rustrt {
|
||||||
#[rust_stack]
|
#[rust_stack]
|
||||||
|
@ -19,12 +16,12 @@ native mod rustrt {
|
||||||
-> libc::intptr_t;
|
-> libc::intptr_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
type arc_data<T> = {
|
type arc_data<T: const> = {
|
||||||
mut count: libc::intptr_t,
|
mut count: libc::intptr_t,
|
||||||
data: T
|
data: T
|
||||||
};
|
};
|
||||||
|
|
||||||
resource arc_destruct<T>(data: *libc::c_void) {
|
resource arc_destruct<T: const>(data: *libc::c_void) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let data: ~arc_data<T> = unsafe::reinterpret_cast(data);
|
let data: ~arc_data<T> = unsafe::reinterpret_cast(data);
|
||||||
let new_count = rustrt::rust_atomic_decrement(&mut data.count);
|
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)
|
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
|
// Convenience code for sharing arcs between tasks
|
||||||
|
|
||||||
type get_chan<T: const send> = chan<chan<arc<T>>>;
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
import comm::*;
|
import comm::*;
|
||||||
import future::future;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn manually_share_arc() {
|
fn manually_share_arc() {
|
||||||
|
@ -201,31 +160,4 @@ mod tests {
|
||||||
|
|
||||||
assert p.recv() == ();
|
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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -19,7 +19,7 @@ export net, net_tcp;
|
||||||
export uv, uv_ll, uv_iotask, uv_global_loop;
|
export uv, uv_ll, uv_iotask, uv_global_loop;
|
||||||
export c_vec, util, timer;
|
export c_vec, util, timer;
|
||||||
export bitv, deque, fun_treemap, list, map, smallintmap, sort, treemap;
|
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 ebml, dbg, getopts, json, rand, sha1, term, time, prettyprint;
|
||||||
export test, tempfile, serialization;
|
export test, tempfile, serialization;
|
||||||
export cmp;
|
export cmp;
|
||||||
|
@ -69,6 +69,7 @@ mod term;
|
||||||
mod time;
|
mod time;
|
||||||
mod prettyprint;
|
mod prettyprint;
|
||||||
mod arena;
|
mod arena;
|
||||||
|
mod arc;
|
||||||
mod par;
|
mod par;
|
||||||
mod cmp;
|
mod cmp;
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import std::map;
|
||||||
import std::map::hashmap;
|
import std::map::hashmap;
|
||||||
import std::deque;
|
import std::deque;
|
||||||
import std::deque::t;
|
import std::deque::t;
|
||||||
|
import std::arc;
|
||||||
import std::par;
|
import std::par;
|
||||||
import io::writer_util;
|
import io::writer_util;
|
||||||
import comm::*;
|
import comm::*;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
// error-pattern: copying a noncopyable value
|
// error-pattern: copying a noncopyable value
|
||||||
|
|
||||||
|
use std;
|
||||||
|
import std::arc;
|
||||||
import comm::*;
|
import comm::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std;
|
||||||
|
import std::arc;
|
||||||
import comm::*;
|
import comm::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
// error-pattern:explicit failure
|
// error-pattern:explicit failure
|
||||||
|
|
||||||
|
use std;
|
||||||
|
import std::arc;
|
||||||
|
|
||||||
enum e<T: const> { e(arc::arc<T>) }
|
enum e<T: const> { e(arc::arc<T>) }
|
||||||
|
|
||||||
fn foo() -> e<int> {fail;}
|
fn foo() -> e<int> {fail;}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue