diff --git a/.gitignore b/.gitignore index a4d7203c2b41a..695525c5bf6f7 100644 --- a/.gitignore +++ b/.gitignore @@ -85,6 +85,7 @@ src/.DS_Store /doc/rustdoc /doc/rustuv /doc/rustpkg +/doc/concurrency /nd/ /llvm/ version.md diff --git a/doc/index.md b/doc/index.md index d3270a96d8036..d4b32229a9b0b 100644 --- a/doc/index.md +++ b/doc/index.md @@ -40,6 +40,7 @@ li {list-style-type: none; } * [The `arena` allocation library](arena/index.html) * [The `flate` compression library](flate/index.html) * [The `glob` file path matching library](glob/index.html) +* [The `sync` mechanisms and primitives library](concurrency/index.html) # Tooling diff --git a/mk/crates.mk b/mk/crates.mk index a8f14bab1e891..a941cfad247ed 100644 --- a/mk/crates.mk +++ b/mk/crates.mk @@ -49,13 +49,13 @@ # automatically generated for all stage/host/target combinations. ################################################################################ -TARGET_CRATES := std extra green rustuv native flate arena glob +TARGET_CRATES := std extra green rustuv native flate arena glob sync HOST_CRATES := syntax rustc rustdoc rustpkg CRATES := $(TARGET_CRATES) $(HOST_CRATES) TOOLS := compiletest rustpkg rustdoc rustc DEPS_std := native:rustrt -DEPS_extra := std +DEPS_extra := std sync DEPS_green := std DEPS_rustuv := std native:uv native:uv_support DEPS_native := std @@ -66,6 +66,7 @@ DEPS_rustpkg := rustc DEPS_flate := std native:miniz DEPS_arena := std extra DEPS_glob := std +DEPS_sync := std TOOL_DEPS_compiletest := extra green rustuv TOOL_DEPS_rustpkg := rustpkg green rustuv diff --git a/src/libextra/lib.rs b/src/libextra/lib.rs index bb89915dfd135..f0ddf96474d8b 100644 --- a/src/libextra/lib.rs +++ b/src/libextra/lib.rs @@ -34,18 +34,12 @@ Rust extras are part of the standard Rust distribution. #[deny(non_camel_case_types)]; #[deny(missing_doc)]; +extern mod sync; + // Utility modules pub mod c_vec; -// Concurrency - -pub mod sync; -pub mod arc; -pub mod comm; -pub mod future; -pub mod task_pool; - // Collections pub mod container; diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index 70bbe02d32f17..8419ec66bad34 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -13,7 +13,7 @@ use json; use json::ToJson; use serialize::{Encoder, Encodable, Decoder, Decodable}; -use arc::{Arc,RWArc}; +use sync::arc::{Arc,RWArc}; use treemap::TreeMap; use std::str; use std::io; diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 90ed4a4c744c5..a09f917730b5c 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -41,7 +41,7 @@ use std::io::{fs, File, BufferedWriter}; use std::str; use std::vec; -use extra::arc::Arc; +use sync::arc::Arc; use extra::json::ToJson; use syntax::ast; use syntax::attr; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index f7a484e3d3e00..2b51dcc8ade2c 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -18,6 +18,7 @@ extern mod syntax; extern mod rustc; extern mod extra; +extern mod sync; use std::local_data; use std::io; diff --git a/src/librustpkg/api.rs b/src/librustpkg/api.rs index 13d5a1177049b..c93f900247928 100644 --- a/src/librustpkg/api.rs +++ b/src/librustpkg/api.rs @@ -21,7 +21,7 @@ pub use path_util::default_workspace; pub use source_control::{safe_git_clone, git_clone_url}; use std::run; -use extra::arc::{Arc,RWArc}; +use sync::arc::{Arc,RWArc}; use extra::workcache; use extra::workcache::{Database, FreshnessMap}; use extra::treemap::TreeMap; diff --git a/src/librustpkg/lib.rs b/src/librustpkg/lib.rs index b43ffec2783ca..56725027126dc 100644 --- a/src/librustpkg/lib.rs +++ b/src/librustpkg/lib.rs @@ -19,6 +19,7 @@ extern mod extra; extern mod rustc; extern mod syntax; +extern mod sync; use std::{os, run, str, task}; use std::io::process; diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index 091399c3fb7de..98ce2861d9292 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -16,8 +16,8 @@ use std::{os, run, str, task}; use std::io; use std::io::fs; use std::io::File; -use extra::arc::Arc; -use extra::arc::RWArc; +use sync::arc::Arc; +use sync::arc::RWArc; use extra::tempfile::TempDir; use extra::workcache; use extra::workcache::Database; diff --git a/src/libextra/arc.rs b/src/libsync/arc.rs similarity index 99% rename from src/libextra/arc.rs rename to src/libsync/arc.rs index bf47e3bdf89ea..fa85ee30d60f5 100644 --- a/src/libextra/arc.rs +++ b/src/libsync/arc.rs @@ -18,7 +18,6 @@ * With simple pipes, without Arc, a copy would have to be made for each task. * * ```rust - * use extra::arc::Arc; * use std::{rand, vec}; * * let numbers = vec::from_fn(100, |i| (i as f32) * rand::random()); @@ -38,9 +37,6 @@ * ``` */ -#[allow(missing_doc)]; - - use sync; use sync::{Mutex, RWLock}; @@ -419,8 +415,6 @@ impl RWArc { * # Example * * ```rust - * use extra::arc::RWArc; - * * let arc = RWArc::new(1); * arc.write_downgrade(|mut write_token| { * write_token.write_cond(|state, condvar| { @@ -556,8 +550,7 @@ impl<'a, T:Freeze + Send> RWReadMode<'a, T> { #[cfg(test)] mod tests { - use arc::*; - + use super::{Arc, RWArc, MutexArc}; use std::task; #[test] diff --git a/src/libextra/comm.rs b/src/libsync/comm.rs similarity index 100% rename from src/libextra/comm.rs rename to src/libsync/comm.rs diff --git a/src/libextra/future.rs b/src/libsync/future.rs similarity index 99% rename from src/libextra/future.rs rename to src/libsync/future.rs index b9121290f33f4..5452a767bb422 100644 --- a/src/libextra/future.rs +++ b/src/libsync/future.rs @@ -15,7 +15,7 @@ * # Example * * ```rust - * use extra::future::Future; + * use concurrency::future::Future; * # fn fib(n: uint) -> uint {42}; * # fn make_a_sandwich() {}; * let mut delayed_fib = Future::spawn(proc() { fib(5000) }); diff --git a/src/libsync/lib.rs b/src/libsync/lib.rs new file mode 100644 index 0000000000000..cf94779059633 --- /dev/null +++ b/src/libsync/lib.rs @@ -0,0 +1,30 @@ +// 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. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +/*! + * Concurrency-enabled mechanisms and primitives. + */ + +#[crate_id = "sync#0.10-pre"]; +#[crate_type = "rlib"]; +#[crate_type = "lib"]; +#[license = "MIT/ASL2"]; + +pub use arc::{Arc, MutexArc, RWArc, RWWriteMode, RWReadMode}; +pub use sync::{Mutex, RWLock, Condvar, Semaphore, RWLockWriteMode, RWLockReadMode}; +pub use comm::{DuplexStream, SyncChan, SyncPort}; +pub use task_pool::TaskPool; +pub use future::Future; + +pub mod arc; +pub mod sync; +pub mod comm; +pub mod task_pool; +pub mod future; diff --git a/src/libextra/sync.rs b/src/libsync/sync.rs similarity index 99% rename from src/libextra/sync.rs rename to src/libsync/sync.rs index 3acaf83525646..2f33f02609a94 100644 --- a/src/libextra/sync.rs +++ b/src/libsync/sync.rs @@ -752,7 +752,7 @@ impl Barrier { #[cfg(test)] mod tests { - use sync::*; + use sync::{RWLock, Mutex, Barrier, Semaphore, Condvar}; use std::cast; use std::result; diff --git a/src/libextra/task_pool.rs b/src/libsync/task_pool.rs similarity index 100% rename from src/libextra/task_pool.rs rename to src/libsync/task_pool.rs diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index b1b2300466a5e..79d095e394230 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -11,14 +11,15 @@ // This test creates a bunch of tasks that simultaneously send to each // other in a ring. The messages should all be basically // independent. -// This is like msgsend-ring-pipes but adapted to use Arcs. +// This is like msgsend-ring-pipes but adapted to use Arc. // This also serves as a pipes test, because Arcs are implemented with pipes. extern mod extra; +extern mod sync; -use extra::arc; -use extra::future::Future; +use sync::arc; +use sync::future::Future; use extra::time; use std::os; use std::uint; diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index d7bd0f2f6bd3d..b5a17ca43040e 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -16,9 +16,10 @@ // This also serves as a pipes test, because Arcs are implemented with pipes. extern mod extra; +extern mod sync; -use extra::arc; -use extra::future::Future; +use sync::arc; +use sync::future::Future; use extra::time; use std::os; use std::uint; diff --git a/src/test/bench/shootout-binarytrees.rs b/src/test/bench/shootout-binarytrees.rs index da658e6d041f7..8179c401400e4 100644 --- a/src/test/bench/shootout-binarytrees.rs +++ b/src/test/bench/shootout-binarytrees.rs @@ -10,9 +10,10 @@ extern mod extra; extern mod arena; +extern mod sync; use std::iter::range_step; -use extra::future::Future; +use sync::future::Future; use arena::TypedArena; enum Tree<'a> { diff --git a/src/test/bench/shootout-spectralnorm.rs b/src/test/bench/shootout-spectralnorm.rs index d68ca4e0abbae..8bb98d54db011 100644 --- a/src/test/bench/shootout-spectralnorm.rs +++ b/src/test/bench/shootout-spectralnorm.rs @@ -10,15 +10,15 @@ // xfail-test arcs no longer unwrap -extern mod extra; +extern mod sync; use std::from_str::FromStr; use std::iter::count; use std::num::min; use std::os; use std::vec::from_elem; -use extra::arc::Arc; -use extra::arc::RWArc; +use sync::arc::Arc; +use sync::arc::RWArc; fn A(i: uint, j: uint) -> f64 { ((i + j) * (i + j + 1) / 2 + i + 1) as f64 diff --git a/src/test/compile-fail/arc-cant-nest-rw-arc-3177.rs b/src/test/compile-fail/arc-cant-nest-rw-arc-3177.rs index 49412b3aafdea..df2977e4ae853 100644 --- a/src/test/compile-fail/arc-cant-nest-rw-arc-3177.rs +++ b/src/test/compile-fail/arc-cant-nest-rw-arc-3177.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern mod extra; -use extra::arc::RWArc; +extern mod sync; +use sync::arc::RWArc; fn main() { let arc1 = RWArc::new(true); diff --git a/src/test/compile-fail/arc-rw-cond-shouldnt-escape.rs b/src/test/compile-fail/arc-rw-cond-shouldnt-escape.rs index c31a7bb244c72..7021119fd4ea2 100644 --- a/src/test/compile-fail/arc-rw-cond-shouldnt-escape.rs +++ b/src/test/compile-fail/arc-rw-cond-shouldnt-escape.rs @@ -9,8 +9,8 @@ // except according to those terms. // error-pattern: lifetime of return value does not outlive the function call -extern mod extra; -use extra::arc; +extern mod sync; +use sync::arc; fn main() { let x = ~arc::RWArc::new(1); let mut y = None; diff --git a/src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs b/src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs index 716dfe2c8b5c5..97c1054c2720a 100644 --- a/src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs +++ b/src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern mod extra; -use extra::arc; +extern mod sync; +use sync::arc; fn main() { let x = ~arc::RWArc::new(1); let mut y = None; diff --git a/src/test/compile-fail/arc-rw-state-shouldnt-escape.rs b/src/test/compile-fail/arc-rw-state-shouldnt-escape.rs index 7c129ae0dcaad..7558e6a21377c 100644 --- a/src/test/compile-fail/arc-rw-state-shouldnt-escape.rs +++ b/src/test/compile-fail/arc-rw-state-shouldnt-escape.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern mod extra; -use extra::arc; +extern mod sync; +use sync::arc; fn main() { let x = ~arc::RWArc::new(1); let mut y = None; //~ ERROR lifetime of variable does not enclose its declaration diff --git a/src/test/compile-fail/arc-rw-write-mode-cond-shouldnt-escape.rs b/src/test/compile-fail/arc-rw-write-mode-cond-shouldnt-escape.rs index 674cd5708889c..539c2e664653f 100644 --- a/src/test/compile-fail/arc-rw-write-mode-cond-shouldnt-escape.rs +++ b/src/test/compile-fail/arc-rw-write-mode-cond-shouldnt-escape.rs @@ -9,8 +9,8 @@ // except according to those terms. // error-pattern: lifetime of variable does not enclose its declaration -extern mod extra; -use extra::arc; +extern mod sync; +use sync::arc; fn main() { let x = ~arc::RWArc::new(1); let mut y = None; diff --git a/src/test/compile-fail/arc-rw-write-mode-shouldnt-escape.rs b/src/test/compile-fail/arc-rw-write-mode-shouldnt-escape.rs index 213bf48a08750..868fa22ae0810 100644 --- a/src/test/compile-fail/arc-rw-write-mode-shouldnt-escape.rs +++ b/src/test/compile-fail/arc-rw-write-mode-shouldnt-escape.rs @@ -9,8 +9,8 @@ // except according to those terms. // error-pattern: lifetime of variable does not enclose its declaration -extern mod extra; -use extra::arc; +extern mod sync; +use sync::arc; fn main() { let x = ~arc::RWArc::new(1); let mut y = None; diff --git a/src/test/compile-fail/functional-struct-update-noncopyable.rs b/src/test/compile-fail/functional-struct-update-noncopyable.rs index 00945ea84693c..c628b31aeab68 100644 --- a/src/test/compile-fail/functional-struct-update-noncopyable.rs +++ b/src/test/compile-fail/functional-struct-update-noncopyable.rs @@ -11,8 +11,8 @@ // issue 7327 // xfail-fast #7103 -extern mod extra; -use extra::arc::Arc; +extern mod sync; +use sync::arc::Arc; struct A { y: Arc, x: Arc } diff --git a/src/test/compile-fail/future_not_copyable.rs b/src/test/compile-fail/future_not_copyable.rs index aef5d0f9b04a6..df70914041f84 100644 --- a/src/test/compile-fail/future_not_copyable.rs +++ b/src/test/compile-fail/future_not_copyable.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern mod extra; +extern mod sync; -use extra::future::Future; +use sync::future::Future; fn main() { let f = Future::from_value(()); diff --git a/src/test/compile-fail/mutex-arc-nested.rs b/src/test/compile-fail/mutex-arc-nested.rs index 24a141c4799d5..ef135aaffc005 100644 --- a/src/test/compile-fail/mutex-arc-nested.rs +++ b/src/test/compile-fail/mutex-arc-nested.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern mod extra; +extern mod sync; use std::task; -use extra::arc::{MutexArc}; +use sync::arc::{MutexArc}; fn test_mutex_arc_nested() { let arc = ~MutexArc::new(1); diff --git a/src/test/compile-fail/no-capture-arc.rs b/src/test/compile-fail/no-capture-arc.rs index 5ae38e69ec0e3..3e05d996b3e79 100644 --- a/src/test/compile-fail/no-capture-arc.rs +++ b/src/test/compile-fail/no-capture-arc.rs @@ -10,8 +10,8 @@ // error-pattern: use of moved value -extern mod extra; -use extra::arc; +extern mod sync; +use sync::arc; use std::task; diff --git a/src/test/compile-fail/no-reuse-move-arc.rs b/src/test/compile-fail/no-reuse-move-arc.rs index c6c0ba41ab91a..7b3651e733deb 100644 --- a/src/test/compile-fail/no-reuse-move-arc.rs +++ b/src/test/compile-fail/no-reuse-move-arc.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern mod extra; -use extra::arc; +extern mod sync; +use sync::arc; use std::task; diff --git a/src/test/compile-fail/once-cant-call-twice-on-heap.rs b/src/test/compile-fail/once-cant-call-twice-on-heap.rs index 8d5e2229b2e5d..1e83a78847596 100644 --- a/src/test/compile-fail/once-cant-call-twice-on-heap.rs +++ b/src/test/compile-fail/once-cant-call-twice-on-heap.rs @@ -12,8 +12,8 @@ // This program would segfault if it were legal. #[feature(once_fns)]; -extern mod extra; -use extra::arc; +extern mod sync; +use sync::arc; fn foo(blk: proc()) { blk(); diff --git a/src/test/compile-fail/once-cant-call-twice-on-stack.rs b/src/test/compile-fail/once-cant-call-twice-on-stack.rs index 71293555d499d..1c5b8997aac2d 100644 --- a/src/test/compile-fail/once-cant-call-twice-on-stack.rs +++ b/src/test/compile-fail/once-cant-call-twice-on-stack.rs @@ -12,8 +12,8 @@ // This program would segfault if it were legal. #[feature(once_fns)]; -extern mod extra; -use extra::arc; +extern mod sync; +use sync::arc; fn foo(blk: once ||) { blk(); diff --git a/src/test/compile-fail/once-cant-move-out-of-non-once-on-stack.rs b/src/test/compile-fail/once-cant-move-out-of-non-once-on-stack.rs index 7206b9bdb88eb..4f4d64e156729 100644 --- a/src/test/compile-fail/once-cant-move-out-of-non-once-on-stack.rs +++ b/src/test/compile-fail/once-cant-move-out-of-non-once-on-stack.rs @@ -11,8 +11,8 @@ // Testing guarantees provided by once functions. // This program would segfault if it were legal. -extern mod extra; -use extra::arc; +extern mod sync; +use sync::arc; fn foo(blk: ||) { blk(); diff --git a/src/test/run-fail/issue-2444.rs b/src/test/run-fail/issue-2444.rs index c1357988f7db5..f21d667299e0c 100644 --- a/src/test/run-fail/issue-2444.rs +++ b/src/test/run-fail/issue-2444.rs @@ -10,8 +10,8 @@ // error-pattern:explicit failure -extern mod extra; -use extra::arc; +extern mod sync; +use sync::arc; enum e { e(arc::Arc) } diff --git a/src/test/run-pass/bind-by-move.rs b/src/test/run-pass/bind-by-move.rs index a7a4aa9885e6e..b32264c0475b3 100644 --- a/src/test/run-pass/bind-by-move.rs +++ b/src/test/run-pass/bind-by-move.rs @@ -9,8 +9,8 @@ // except according to those terms. // xfail-fast -extern mod extra; -use extra::arc; +extern mod sync; +use sync::arc; fn dispose(_x: arc::Arc) { } pub fn main() { diff --git a/src/test/run-pass/once-move-out-on-heap.rs b/src/test/run-pass/once-move-out-on-heap.rs index bc56712ee3bc1..bb6793819e494 100644 --- a/src/test/run-pass/once-move-out-on-heap.rs +++ b/src/test/run-pass/once-move-out-on-heap.rs @@ -13,8 +13,8 @@ // xfail-fast #[feature(once_fns)]; -extern mod extra; -use extra::arc; +extern mod sync; +use sync::arc; fn foo(blk: proc()) { blk(); diff --git a/src/test/run-pass/once-move-out-on-stack.rs b/src/test/run-pass/once-move-out-on-stack.rs index 07dd5175a0fae..abfb92d48b070 100644 --- a/src/test/run-pass/once-move-out-on-stack.rs +++ b/src/test/run-pass/once-move-out-on-stack.rs @@ -13,8 +13,8 @@ // xfail-fast #[feature(once_fns)]; -extern mod extra; -use extra::arc; +extern mod sync; +use sync::arc; fn foo(blk: once ||) { blk(); diff --git a/src/test/run-pass/trait-bounds-in-arc.rs b/src/test/run-pass/trait-bounds-in-arc.rs index 2bf18e1ae1d5f..d3aa3fbc0de85 100644 --- a/src/test/run-pass/trait-bounds-in-arc.rs +++ b/src/test/run-pass/trait-bounds-in-arc.rs @@ -15,9 +15,9 @@ // xfail-fast -extern mod extra; +extern mod sync; -use extra::arc; +use sync::arc; use std::task; trait Pet {