auto merge of #12900 : alexcrichton/rust/rewrite-sync, r=brson
* Remove clone-ability from all primitives. All shared state will now come
from the usage of the primitives being shared, not the primitives being
inherently shareable. This allows for fewer allocations for stack-allocated
primitives.
* Add `Mutex<T>` and `RWLock<T>` which are stack-allocated primitives for purely
wrapping a piece of data
* Remove `RWArc<T>` in favor of `Arc<RWLock<T>>`
* Remove `MutexArc<T>` in favor of `Arc<Mutex<T>>`
* Shuffle around where things are located
* The `arc` module now only contains `Arc`
* A new `lock` module contains `Mutex`, `RWLock`, and `Barrier`
* A new `raw` module contains the primitive implementations of `Semaphore`,
`Mutex`, and `RWLock`
* The Deref/DerefMut trait was implemented where appropriate
* `CowArc` was removed, the functionality is now part of `Arc` and is tagged
with `#[experimental]`.
* The crate now has #[deny(missing_doc)]
* `Arc` now supports weak pointers
This is not a large-scale rewrite of the functionality contained within the
`sync` crate, but rather a shuffling of who does what an a thinner hierarchy of
ownership to allow for better composability.
This commit is contained in:
commit
6bf3fca8ff
48 changed files with 1738 additions and 2045 deletions
|
|
@ -1,17 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
extern crate sync;
|
||||
use sync::RWArc;
|
||||
|
||||
fn main() {
|
||||
let arc1 = RWArc::new(true);
|
||||
let _arc2 = RWArc::new(arc1); //~ ERROR instantiating a type parameter with an incompatible type
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern: lifetime of return value does not outlive the function call
|
||||
extern crate sync;
|
||||
use sync::RWArc;
|
||||
fn main() {
|
||||
let x = ~RWArc::new(1);
|
||||
let mut y = None;
|
||||
x.write_cond(|_one, cond| y = Some(cond));
|
||||
y.unwrap().wait();
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
extern crate sync;
|
||||
use sync::RWArc;
|
||||
fn main() {
|
||||
let x = ~RWArc::new(1);
|
||||
let mut y = None;
|
||||
x.write_downgrade(|write_mode| {
|
||||
y = Some(x.downgrade(write_mode));
|
||||
//~^ ERROR cannot infer
|
||||
});
|
||||
y.unwrap();
|
||||
// Adding this line causes a method unification failure instead
|
||||
// (&option::unwrap(y)).read(|state| { assert!(*state == 1); })
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
extern crate sync;
|
||||
use sync::RWArc;
|
||||
fn main() {
|
||||
let x = ~RWArc::new(1);
|
||||
let mut y = None; //~ ERROR lifetime of variable does not enclose its declaration
|
||||
x.write(|one| y = Some(one));
|
||||
*y.unwrap() = 2;
|
||||
//~^ ERROR lifetime of return value does not outlive the function call
|
||||
//~^^ ERROR dereference of reference outside its lifetime
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern: lifetime of variable does not enclose its declaration
|
||||
extern crate sync;
|
||||
use sync::RWArc;
|
||||
fn main() {
|
||||
let x = ~RWArc::new(1);
|
||||
let mut y = None;
|
||||
x.write_downgrade(|write_mode| {
|
||||
(&write_mode).write_cond(|_one, cond| {
|
||||
y = Some(cond);
|
||||
})
|
||||
});
|
||||
y.unwrap().wait();
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern: lifetime of variable does not enclose its declaration
|
||||
extern crate sync;
|
||||
use sync::RWArc;
|
||||
fn main() {
|
||||
let x = ~RWArc::new(1);
|
||||
let mut y = None;
|
||||
x.write_downgrade(|write_mode| y = Some(write_mode));
|
||||
y.unwrap();
|
||||
// Adding this line causes a method unification failure instead
|
||||
// (&option::unwrap(y)).write(|state| { assert!(*state == 1); })
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ use sync::Arc;
|
|||
struct A { y: Arc<int>, x: Arc<int> }
|
||||
|
||||
impl Drop for A {
|
||||
fn drop(&mut self) { println!("x={:?}", self.x.get()); }
|
||||
fn drop(&mut self) { println!("x={}", *self.x); }
|
||||
}
|
||||
fn main() {
|
||||
let a = A { y: Arc::new(1), x: Arc::new(2) };
|
||||
|
|
|
|||
|
|
@ -20,11 +20,10 @@ fn main() {
|
|||
let arc_v = Arc::new(v);
|
||||
|
||||
task::spawn(proc() {
|
||||
let v = arc_v.get();
|
||||
assert_eq!(*v.get(3), 4);
|
||||
assert_eq!(*arc_v.get(3), 4);
|
||||
});
|
||||
|
||||
assert_eq!(*(arc_v.get()).get(2), 3);
|
||||
assert_eq!(*arc_v.get(2), 3);
|
||||
|
||||
println!("{:?}", arc_v);
|
||||
println!("{}", *arc_v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,10 @@ fn main() {
|
|||
let arc_v = Arc::new(v);
|
||||
|
||||
task::spawn(proc() {
|
||||
let v = arc_v.get();
|
||||
assert_eq!(*v.get(3), 4);
|
||||
assert_eq!(*arc_v.get(3), 4);
|
||||
});
|
||||
|
||||
assert_eq!(*(arc_v.get()).get(2), 3); //~ ERROR use of moved value: `arc_v`
|
||||
assert_eq!(*arc_v.get(2), 3); //~ ERROR use of moved value: `arc_v`
|
||||
|
||||
println!("{:?}", arc_v); //~ ERROR use of moved value: `arc_v`
|
||||
println!("{}", *arc_v); //~ ERROR use of moved value: `arc_v`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ fn foo(blk: proc()) {
|
|||
fn main() {
|
||||
let x = Arc::new(true);
|
||||
foo(proc() {
|
||||
assert!(*x.get());
|
||||
assert!(*x);
|
||||
drop(x);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ fn foo(blk: once ||) {
|
|||
fn main() {
|
||||
let x = Arc::new(true);
|
||||
foo(|| {
|
||||
assert!(*x.get());
|
||||
assert!(*x);
|
||||
drop(x);
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ fn foo(blk: ||) {
|
|||
fn main() {
|
||||
let x = Arc::new(true);
|
||||
foo(|| {
|
||||
assert!(*x.get());
|
||||
assert!(*x);
|
||||
drop(x); //~ ERROR cannot move out of captured outer variable
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern: lifetime of variable does not enclose its declaration
|
||||
extern crate sync;
|
||||
use sync::Mutex;
|
||||
|
||||
fn main() {
|
||||
let m = ~sync::Mutex::new();
|
||||
let mut cond = None;
|
||||
m.lock_cond(|c| {
|
||||
cond = Some(c);
|
||||
});
|
||||
cond.unwrap().signal();
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern: lifetime of method receiver does not outlive the method call
|
||||
extern crate sync;
|
||||
use sync::RWLock;
|
||||
fn main() {
|
||||
let x = ~RWLock::new();
|
||||
let mut y = None;
|
||||
x.write_cond(|cond| {
|
||||
y = Some(cond);
|
||||
});
|
||||
y.unwrap().wait();
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern: cannot infer
|
||||
extern crate sync;
|
||||
use sync::RWLock;
|
||||
fn main() {
|
||||
let x = ~RWLock::new();
|
||||
let mut y = None;
|
||||
x.write_downgrade(|write_mode| {
|
||||
y = Some(x.downgrade(write_mode));
|
||||
})
|
||||
// Adding this line causes a method unification failure instead
|
||||
// (&option::unwrap(y)).read(proc() { });
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern: lifetime of variable does not enclose its declaration
|
||||
extern crate sync;
|
||||
use sync::RWLock;
|
||||
fn main() {
|
||||
let x = ~RWLock::new();
|
||||
let mut y = None;
|
||||
x.write_downgrade(|write_mode| {
|
||||
(&write_mode).write_cond(|cond| {
|
||||
y = Some(cond);
|
||||
})
|
||||
});
|
||||
y.unwrap().wait();
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern: lifetime of variable does not enclose its declaration
|
||||
extern crate sync;
|
||||
use sync::RWLock;
|
||||
fn main() {
|
||||
let x = ~RWLock::new();
|
||||
let mut y = None;
|
||||
x.write_downgrade(|write_mode| {
|
||||
y = Some(write_mode);
|
||||
});
|
||||
// Adding this line causes a method unification failure instead
|
||||
// (&option::unwrap(y)).write(proc() { })
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue