Skip to content

Commit

Permalink
auto merge of #14746 : alexcrichton/rust/libsync, r=brson
Browse files Browse the repository at this point in the history
This commit is the final step in the libstd facade, #13851. The purpose of this
commit is to move libsync underneath the standard library, behind the facade.
This will allow core primitives like channels, queues, and atomics to all live
in the same location.

There were a few notable changes and a few breaking changes as part of this
movement:

* The `Vec` and `String` types are reexported at the top level of libcollections
* The `unreachable!()` macro was copied to libcore
* The `std::rt::thread` module was moved to librustrt, but it is still
  reexported at the same location.
* The `std::comm` module was moved to libsync
* The `sync::comm` module was moved under `sync::comm`, and renamed to `duplex`.
  It is now a private module with types/functions being reexported under
  `sync::comm`. This is a breaking change for any existing users of duplex
  streams.
* All concurrent queues/deques were moved directly under libsync. They are also
  all marked with #![experimental] for now if they are public.
* The `task_pool` and `future` modules no longer live in libsync, but rather
  live under `std::sync`. They will forever live at this location, but they may
  move to libsync if the `std::task` module moves as well.

[breaking-change]
  • Loading branch information
bors committed Jun 11, 2014
2 parents f0f9095 + b1c9ce9 commit f9260d4
Show file tree
Hide file tree
Showing 61 changed files with 382 additions and 361 deletions.
12 changes: 6 additions & 6 deletions mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ DEPS_rlibc :=
DEPS_alloc := core libc native:jemalloc
DEPS_debug := std
DEPS_rustrt := alloc core libc collections native:rustrt_native
DEPS_std := core libc rand alloc collections rustrt \
DEPS_std := core libc rand alloc collections rustrt sync \
native:rust_builtin native:backtrace
DEPS_graphviz := std
DEPS_green := std native:context_switch
DEPS_rustuv := std native:uv native:uv_support
DEPS_native := std
DEPS_syntax := std term serialize log fmt_macros debug
DEPS_rustc := syntax native:rustllvm flate arena serialize sync getopts \
DEPS_rustc := syntax native:rustllvm flate arena serialize getopts \
time log graphviz debug
DEPS_rustdoc := rustc native:hoedown serialize sync getopts \
DEPS_rustdoc := rustc native:hoedown serialize getopts \
test time debug
DEPS_flate := std native:miniz
DEPS_arena := std
Expand All @@ -80,17 +80,17 @@ DEPS_serialize := std log
DEPS_term := std log
DEPS_semver := std
DEPS_uuid := std serialize
DEPS_sync := std alloc
DEPS_sync := core alloc rustrt collections
DEPS_getopts := std
DEPS_collections := core alloc
DEPS_fourcc := rustc syntax std
DEPS_hexfloat := rustc syntax std
DEPS_num := std
DEPS_test := std getopts serialize term time regex native:rust_test_helpers
DEPS_time := std serialize sync
DEPS_time := std serialize
DEPS_rand := core
DEPS_url := std
DEPS_log := std sync
DEPS_log := std
DEPS_regex := std
DEPS_regex_macros = rustc syntax std regex
DEPS_fmt_macros = std
Expand Down
30 changes: 13 additions & 17 deletions src/doc/guide-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ later.
The basic example below illustrates this.

~~~
extern crate sync;
use std::sync::Future;
# fn main() {
# fn make_a_sandwich() {};
Expand All @@ -278,7 +278,7 @@ fn fib(n: u64) -> u64 {
12586269025
}
let mut delayed_fib = sync::Future::spawn(proc() fib(50));
let mut delayed_fib = Future::spawn(proc() fib(50));
make_a_sandwich();
println!("fib(50) = {}", delayed_fib.get())
# }
Expand All @@ -294,7 +294,7 @@ Here is another example showing how futures allow you to background computations
be distributed on the available cores.

~~~
# extern crate sync;
# use std::sync::Future;
fn partial_sum(start: uint) -> f64 {
let mut local_sum = 0f64;
for num in range(start*100000, (start+1)*100000) {
Expand All @@ -304,7 +304,7 @@ fn partial_sum(start: uint) -> f64 {
}
fn main() {
let mut futures = Vec::from_fn(1000, |ind| sync::Future::spawn( proc() { partial_sum(ind) }));
let mut futures = Vec::from_fn(1000, |ind| Future::spawn( proc() { partial_sum(ind) }));
let mut final_res = 0f64;
for ft in futures.mut_iter() {
Expand All @@ -329,10 +329,8 @@ Here is a small example showing how to use Arcs. We wish to run concurrently sev
a single large vector of floats. Each task needs the full vector to perform its duty.

~~~
extern crate sync;
use sync::Arc;
use std::rand;
use std::sync::Arc;
fn pnorm(nums: &[f64], p: uint) -> f64 {
nums.iter().fold(0.0, |a, b| a + b.powf(p as f64)).powf(1.0 / (p as f64))
Expand All @@ -357,9 +355,8 @@ at the power given as argument and takes the inverse power of this value). The A
created by the line

~~~
# extern crate sync;
# use std::rand;
# use sync::Arc;
# use std::sync::Arc;
# fn main() {
# let numbers = Vec::from_fn(1000000, |_| rand::random::<f64>());
let numbers_arc=Arc::new(numbers);
Expand All @@ -371,9 +368,8 @@ it's contents. Within the task's procedure, the captured Arc reference can be us
reference to the underlying vector as if it were local.

~~~
# extern crate sync;
# use std::rand;
# use sync::Arc;
# use std::sync::Arc;
# fn pnorm(nums: &[f64], p: uint) -> f64 { 4.0 }
# fn main() {
# let numbers=Vec::from_fn(1000000, |_| rand::random::<f64>());
Expand Down Expand Up @@ -461,9 +457,9 @@ the string in response. The child terminates when it receives `0`.
Here is the function that implements the child task:

~~~
extern crate sync;
use std::comm::DuplexStream;
# fn main() {
fn stringifier(channel: &sync::DuplexStream<String, uint>) {
fn stringifier(channel: &DuplexStream<String, uint>) {
let mut value: uint;
loop {
value = channel.recv();
Expand All @@ -485,10 +481,10 @@ response itself is simply the stringified version of the received value,
Here is the code for the parent task:

~~~
extern crate sync;
use std::comm::duplex;
# use std::task::spawn;
# use sync::DuplexStream;
# fn stringifier(channel: &sync::DuplexStream<String, uint>) {
# use std::comm::DuplexStream;
# fn stringifier(channel: &DuplexStream<String, uint>) {
# let mut value: uint;
# loop {
# value = channel.recv();
Expand All @@ -498,7 +494,7 @@ extern crate sync;
# }
# fn main() {
let (from_child, to_child) = sync::duplex();
let (from_child, to_child) = duplex();
spawn(proc() {
stringifier(&to_child);
Expand Down
6 changes: 2 additions & 4 deletions src/doc/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ an atomically reference counted box ("A.R.C." == "atomically reference counted")
Here's some code:

```
extern crate sync;
use sync::Arc;
use std::sync::Arc;
fn main() {
let numbers = vec![1,2,3];
Expand Down Expand Up @@ -344,8 +343,7 @@ Let's take the same example yet again,
and modify it to mutate the shared state:

```
extern crate sync;
use sync::{Arc, Mutex};
use std::sync::{Arc, Mutex};
fn main() {
let numbers = vec![1,2,3];
Expand Down
6 changes: 3 additions & 3 deletions src/etc/licenseck.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
"rt/isaac/randport.cpp", # public domain
"rt/isaac/rand.h", # public domain
"rt/isaac/standard.h", # public domain
"libstd/sync/mpsc_queue.rs", # BSD
"libstd/sync/spsc_queue.rs", # BSD
"libstd/sync/mpmc_bounded_queue.rs", # BSD
"libsync/mpsc_queue.rs", # BSD
"libsync/spsc_queue.rs", # BSD
"libsync/mpmc_bounded_queue.rs", # BSD
"libsync/mpsc_intrusive.rs", # BSD
"test/bench/shootout-fannkuch-redux.rs", # BSD
"test/bench/shootout-meteor.rs", # BSD
Expand Down
6 changes: 2 additions & 4 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ use heap::deallocate;
/// task.
///
/// ```rust
/// extern crate sync;
///
/// use sync::Arc;
/// use std::sync::Arc;
///
/// fn main() {
/// let numbers = Vec::from_fn(100, |i| i as f32);
Expand Down Expand Up @@ -276,7 +274,7 @@ mod tests {
use std::task;
use std::vec::Vec;
use super::{Arc, Weak};
use sync::Mutex;
use std::sync::Mutex;

struct Canary(*mut atomics::AtomicUint);

Expand Down
1 change: 0 additions & 1 deletion src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ extern crate libc;
// Allow testing this library

#[cfg(test)] extern crate debug;
#[cfg(test)] extern crate sync;
#[cfg(test)] extern crate native;
#[cfg(test, stage0)] #[phase(syntax, link)] extern crate std;
#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
Expand Down
2 changes: 2 additions & 0 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ pub use enum_set::EnumSet;
pub use priority_queue::PriorityQueue;
pub use ringbuf::RingBuf;
pub use smallintmap::SmallIntMap;
pub use string::String;
pub use treemap::{TreeMap, TreeSet};
pub use trie::{TrieMap, TrieSet};
pub use vec::Vec;

mod macros;

Expand Down
12 changes: 5 additions & 7 deletions src/libcore/atomics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,14 @@ impl AtomicBool {
///
/// # Examples
///
/// ```ignore
/// # // FIXME: Needs PR #12430
/// extern crate sync;
///
/// use sync::Arc;
/// ```rust
/// use std::sync::Arc;
/// use std::sync::atomics::{AtomicBool, SeqCst};
/// use std::task::deschedule;
///
/// fn main() {
/// let spinlock = Arc::new(AtomicBool::new(false));
/// let spinlock_clone = spin_lock.clone();
/// let spinlock_clone = spinlock.clone();
///
/// spawn(proc() {
/// with_lock(&spinlock, || println!("task 1 in lock"));
Expand All @@ -155,7 +153,7 @@ impl AtomicBool {
/// f();
///
/// // Release the lock
/// spinlock.store(false);
/// spinlock.store(false, SeqCst);
/// }
/// ```
#[inline]
Expand Down
3 changes: 3 additions & 0 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ macro_rules! write(
format_args_method!($dst, write_fmt, $($arg)*)
})
)

#[macro_export]
macro_rules! unreachable( () => (fail!("unreachable code")) )
5 changes: 1 addition & 4 deletions src/liblog/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,14 @@ if logging is disabled, none of the components of the log will be executed.
#![feature(macro_rules)]
#![deny(missing_doc, deprecated_owned_vector)]

extern crate sync;

use std::fmt;
use std::io::LineBufferedWriter;
use std::io;
use std::mem;
use std::os;
use std::rt;
use std::slice;

use sync::one::{Once, ONCE_INIT};
use std::sync::{Once, ONCE_INIT};

use directive::LOG_LEVEL_NAMES;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ pub mod write {
}

unsafe fn configure_llvm(sess: &Session) {
use sync::one::{Once, ONCE_INIT};
use std::sync::{Once, ONCE_INIT};
static mut INIT: Once = ONCE_INIT;

// Copy what clang does by turning on loop vectorization at O2 and
Expand Down
1 change: 0 additions & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ extern crate getopts;
extern crate graphviz;
extern crate libc;
extern crate serialize;
extern crate sync;
extern crate syntax;
extern crate time;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2297,7 +2297,7 @@ pub fn trans_crate(krate: ast::Crate,

// Before we touch LLVM, make sure that multithreading is enabled.
unsafe {
use sync::one::{Once, ONCE_INIT};
use std::sync::{Once, ONCE_INIT};
static mut INIT: Once = ONCE_INIT;
static mut POISONED: bool = false;
INIT.doit(|| {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ use std::io::{fs, File, BufferedWriter, MemWriter, BufferedReader};
use std::io;
use std::str;
use std::string::String;
use std::sync::Arc;

use sync::Arc;
use serialize::json::ToJson;
use syntax::ast;
use syntax::ast_util;
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ extern crate getopts;
extern crate libc;
extern crate rustc;
extern crate serialize;
extern crate sync;
extern crate syntax;
extern crate testing = "test";
extern crate time;
Expand Down
6 changes: 4 additions & 2 deletions src/librustrt/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/")]
#![feature(macro_rules, phase, globs, thread_local, managed_boxes, asm)]
#![feature(macro_rules, phase, globs, thread_local, managed_boxes, asm,
linkage)]
#![no_std]
#![experimental]

Expand Down Expand Up @@ -58,6 +59,7 @@ mod libunwind;

pub mod args;
pub mod bookkeeping;
pub mod c_str;
pub mod exclusive;
pub mod local;
pub mod local_data;
Expand All @@ -66,8 +68,8 @@ pub mod mutex;
pub mod rtio;
pub mod stack;
pub mod task;
pub mod thread;
pub mod unwind;
pub mod c_str;

/// The interface to the current runtime.
///
Expand Down
Loading

0 comments on commit f9260d4

Please sign in to comment.