Skip to content

Commit 6bf3fca

Browse files
committed
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.
2 parents bcaaffb + 218461d commit 6bf3fca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1727
-2034
lines changed

src/compiletest/compiletest.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#[feature(phase)];
1313

1414
#[allow(non_camel_case_types)];
15-
#[allow(deprecated_owned_vector)]; // NOTE: remove after stage0
1615
#[deny(warnings)];
1716

1817
extern crate test;

src/doc/guide-tasks.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ fn main() {
359359
360360
spawn(proc() {
361361
let local_arc : Arc<~[f64]> = rx.recv();
362-
let task_numbers = local_arc.get();
362+
let task_numbers = &*local_arc;
363363
println!("{}-norm = {}", num, pnorm(task_numbers, num));
364364
});
365365
}
@@ -411,7 +411,7 @@ Each task recovers the underlying data by
411411
# let (tx, rx) = channel();
412412
# tx.send(numbers_arc.clone());
413413
# let local_arc : Arc<~[f64]> = rx.recv();
414-
let task_numbers = local_arc.get();
414+
let task_numbers = &*local_arc;
415415
# }
416416
~~~
417417

src/driver/driver.rs

-5
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,4 @@ extern crate this = "rustdoc";
1414
#[cfg(rustc)]
1515
extern crate this = "rustc";
1616

17-
#[cfg(not(stage0))]
1817
fn main() { this::main() }
19-
20-
#[cfg(stage0)]
21-
#[start]
22-
fn start(argc: int, argv: **u8) -> int { native::start(argc, argv, this::main) }

src/etc/licenseck.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"libstd/sync/mpsc_queue.rs", # BSD
4242
"libstd/sync/spsc_queue.rs", # BSD
4343
"libstd/sync/mpmc_bounded_queue.rs", # BSD
44-
"libsync/sync/mpsc_intrusive.rs", # BSD
44+
"libsync/mpsc_intrusive.rs", # BSD
4545
]
4646

4747
def check_license(name, contents):

src/libgreen/lib.rs

-10
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,6 @@ pub mod sleeper_list;
207207
pub mod stack;
208208
pub mod task;
209209

210-
#[lang = "start"]
211-
#[cfg(not(test), stage0)]
212-
pub fn lang_start(main: *u8, argc: int, argv: **u8) -> int {
213-
use std::cast;
214-
start(argc, argv, proc() {
215-
let main: extern "Rust" fn() = unsafe { cast::transmute(main) };
216-
main();
217-
})
218-
}
219-
220210
/// Set up a default runtime configuration, given compiler-supplied arguments.
221211
///
222212
/// This function will block until the entire pool of M:N schedulers have

src/libgreen/simple.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Runtime for SimpleTask {
4040
// See libnative/task.rs for what's going on here with the `awoken`
4141
// field and the while loop around wait()
4242
unsafe {
43-
let mut guard = (*me).lock.lock();
43+
let guard = (*me).lock.lock();
4444
(*me).awoken = false;
4545
match f(task) {
4646
Ok(()) => {
@@ -60,7 +60,7 @@ impl Runtime for SimpleTask {
6060
to_wake.put_runtime(self as ~Runtime);
6161
unsafe {
6262
cast::forget(to_wake);
63-
let mut guard = (*me).lock.lock();
63+
let guard = (*me).lock.lock();
6464
(*me).awoken = true;
6565
guard.signal();
6666
}

src/libnative/io/timer_helper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn send(req: Req) {
7575
fn shutdown() {
7676
// Request a shutdown, and then wait for the task to exit
7777
unsafe {
78-
let mut guard = TIMER_HELPER_EXIT.lock();
78+
let guard = TIMER_HELPER_EXIT.lock();
7979
send(Shutdown);
8080
guard.wait();
8181
drop(guard);

src/libnative/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static OS_DEFAULT_STACK_ESTIMATE: uint = 1 << 20;
6969
static OS_DEFAULT_STACK_ESTIMATE: uint = 2 * (1 << 20);
7070

7171
#[lang = "start"]
72-
#[cfg(not(test), not(stage0))]
72+
#[cfg(not(test))]
7373
pub fn lang_start(main: *u8, argc: int, argv: **u8) -> int {
7474
use std::cast;
7575
start(argc, argv, proc() {

src/libnative/task.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl rt::Runtime for Ops {
190190
let task = BlockedTask::block(cur_task);
191191

192192
if times == 1 {
193-
let mut guard = (*me).lock.lock();
193+
let guard = (*me).lock.lock();
194194
(*me).awoken = false;
195195
match f(task) {
196196
Ok(()) => {
@@ -202,7 +202,7 @@ impl rt::Runtime for Ops {
202202
}
203203
} else {
204204
let mut iter = task.make_selectable(times);
205-
let mut guard = (*me).lock.lock();
205+
let guard = (*me).lock.lock();
206206
(*me).awoken = false;
207207
let success = iter.all(|task| {
208208
match f(task) {
@@ -232,7 +232,7 @@ impl rt::Runtime for Ops {
232232
let me = &mut *self as *mut Ops;
233233
to_wake.put_runtime(self as ~rt::Runtime);
234234
cast::forget(to_wake);
235-
let mut guard = (*me).lock.lock();
235+
let guard = (*me).lock.lock();
236236
(*me).awoken = true;
237237
guard.signal();
238238
}

src/librustdoc/html/format.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
208208
let loc = loc.unwrap();
209209

210210
local_data::get(cache_key, |cache| {
211-
let cache = cache.unwrap().get();
212-
let abs_root = root(cache, loc.as_slice());
211+
let cache = cache.unwrap();
212+
let abs_root = root(&**cache, loc.as_slice());
213213
let rel_root = match path.segments.get(0).name.as_slice() {
214214
"self" => Some(~"./"),
215215
_ => None,
@@ -241,7 +241,7 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
241241
}
242242
}
243243

244-
match info(cache) {
244+
match info(&**cache) {
245245
// This is a documented path, link to it!
246246
Some((ref fqp, shortty)) if abs_root.is_some() => {
247247
let mut url = abs_root.unwrap();
@@ -301,7 +301,7 @@ impl fmt::Show for clean::Type {
301301
match *self {
302302
clean::TyParamBinder(id) | clean::Generic(id) => {
303303
local_data::get(cache_key, |cache| {
304-
let m = cache.unwrap().get();
304+
let m = cache.unwrap();
305305
f.buf.write(m.typarams.get(&id).as_bytes())
306306
})
307307
}

src/librustdoc/html/render.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ fn item_trait(w: &mut Writer, it: &clean::Item,
12651265
}
12661266

12671267
local_data::get(cache_key, |cache| {
1268-
let cache = cache.unwrap().get();
1268+
let cache = cache.unwrap();
12691269
match cache.implementors.find(&it.id) {
12701270
Some(implementors) => {
12711271
try!(write!(w, "
@@ -1496,7 +1496,7 @@ fn render_struct(w: &mut Writer, it: &clean::Item,
14961496

14971497
fn render_methods(w: &mut Writer, it: &clean::Item) -> fmt::Result {
14981498
local_data::get(cache_key, |cache| {
1499-
let c = cache.unwrap().get();
1499+
let c = cache.unwrap();
15001500
match c.impls.find(&it.id) {
15011501
Some(v) => {
15021502
let mut non_trait = v.iter().filter(|p| {
@@ -1576,7 +1576,7 @@ fn render_impl(w: &mut Writer, i: &clean::Impl,
15761576
Some(id) => id,
15771577
};
15781578
try!(local_data::get(cache_key, |cache| {
1579-
let cache = cache.unwrap().get();
1579+
let cache = cache.unwrap();
15801580
match cache.traits.find(&trait_id) {
15811581
Some(t) => {
15821582
let name = meth.name.clone();
@@ -1606,7 +1606,7 @@ fn render_impl(w: &mut Writer, i: &clean::Impl,
16061606
None => {}
16071607
Some(id) => {
16081608
try!(local_data::get(cache_key, |cache| {
1609-
let cache = cache.unwrap().get();
1609+
let cache = cache.unwrap();
16101610
match cache.traits.find(&id) {
16111611
Some(t) => {
16121612
for method in t.methods.iter() {

src/libstd/comm/shared.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub enum Failure {
6868
impl<T: Send> Packet<T> {
6969
// Creation of a packet *must* be followed by a call to inherit_blocker
7070
pub fn new() -> Packet<T> {
71-
let mut p = Packet {
71+
let p = Packet {
7272
queue: mpsc::Queue::new(),
7373
cnt: atomics::AtomicInt::new(0),
7474
steals: 0,

src/libstd/intrinsics.rs

-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ pub trait TyVisitor {
164164
fn visit_self(&mut self) -> bool;
165165
}
166166

167-
168167
extern "rust-intrinsic" {
169168

170169
// NB: These intrinsics take unsafe pointers because they mutate aliased

src/libstd/rt/bookkeeping.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn increment() {
3434
pub fn decrement() {
3535
unsafe {
3636
if TASK_COUNT.fetch_sub(1, atomics::SeqCst) == 1 {
37-
let mut guard = TASK_LOCK.lock();
37+
let guard = TASK_LOCK.lock();
3838
guard.signal();
3939
}
4040
}
@@ -44,7 +44,7 @@ pub fn decrement() {
4444
/// the entry points of native programs
4545
pub fn wait_for_other_tasks() {
4646
unsafe {
47-
let mut guard = TASK_LOCK.lock();
47+
let guard = TASK_LOCK.lock();
4848
while TASK_COUNT.load(atomics::SeqCst) > 0 {
4949
guard.wait();
5050
}

src/libstd/sync/atomics.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
//!
4040
//! A simple spinlock:
4141
//!
42-
//! ```ignore
43-
//! # // FIXME: Needs PR #12430
42+
//! ```
4443
//! extern crate sync;
4544
//!
4645
//! use sync::Arc;
@@ -68,8 +67,7 @@
6867
//!
6968
//! Transferring a heap object with `AtomicOption`:
7069
//!
71-
//! ```ignore
72-
//! # // FIXME: Needs PR #12430
70+
//! ```
7371
//! extern crate sync;
7472
//!
7573
//! use sync::Arc;

0 commit comments

Comments
 (0)