auto merge of #19255 : aturon/rust/merge-sync, r=alexcrichton,alexcrichton

This patch merges the `libsync` crate into `libstd`, undoing part of the
facade. This is in preparation for ultimately merging `librustrt`, as
well as the upcoming rewrite of `sync`.

Because this removes the `libsync` crate, it is a:

[breaking-change]

However, all uses of `libsync` should be able to reroute through
`std::sync` and `std::comm` instead.

r? @alexcrichton
This commit is contained in:
bors 2014-11-25 20:32:20 +00:00
commit 689ef2dabf
20 changed files with 103 additions and 159 deletions

View file

@ -50,7 +50,7 @@
################################################################################
TARGET_CRATES := libc std flate arena term \
serialize sync getopts collections test time rand \
serialize getopts collections test time rand \
log regex graphviz core rbml alloc rustrt \
unicode
HOST_CRATES := syntax rustc rustc_trans rustdoc regex_macros fmt_macros \
@ -63,7 +63,7 @@ DEPS_libc := core
DEPS_unicode := core
DEPS_alloc := core libc native:jemalloc
DEPS_rustrt := alloc core libc collections native:rustrt_native
DEPS_std := core libc rand alloc collections rustrt sync unicode \
DEPS_std := core libc rand alloc collections rustrt unicode \
native:rust_builtin native:backtrace
DEPS_graphviz := std
DEPS_syntax := std term serialize log fmt_macros arena libc
@ -81,7 +81,6 @@ DEPS_glob := std
DEPS_serialize := std log
DEPS_rbml := std log serialize
DEPS_term := std log
DEPS_sync := core alloc rustrt collections
DEPS_getopts := std
DEPS_collections := core alloc unicode
DEPS_num := std

View file

@ -38,10 +38,9 @@ exceptions = [
"rt/isaac/randport.cpp", # public domain
"rt/isaac/rand.h", # public domain
"rt/isaac/standard.h", # public domain
"libsync/mpsc_queue.rs", # BSD
"libsync/spsc_queue.rs", # BSD
"libsync/mpmc_bounded_queue.rs", # BSD
"libsync/mpsc_intrusive.rs", # BSD
"libstd/sync/mpsc_queue.rs", # BSD
"libstd/sync/spsc_queue.rs", # BSD
"libstd/sync/mpmc_bounded_queue.rs", # BSD
"test/bench/shootout-binarytrees.rs", # BSD
"test/bench/shootout-chameneos-redux.rs", # BSD
"test/bench/shootout-fannkuch-redux.rs", # BSD

View file

@ -338,12 +338,11 @@ macro_rules! test (
extern crate rustrt;
use std::prelude::*;
use prelude::*;
use comm::*;
use super::*;
use super::super::*;
use std::task;
use task;
$(#[$a])* #[test] fn f() { $b }
}
@ -1019,9 +1018,9 @@ impl<T: Send> Drop for Receiver<T> {
#[cfg(test)]
mod test {
use std::prelude::*;
use prelude::*;
use std::os;
use os;
use super::*;
pub fn stress_factor() -> uint {
@ -1554,8 +1553,8 @@ mod test {
#[cfg(test)]
mod sync_tests {
use std::prelude::*;
use std::os;
use prelude::*;
use os;
pub fn stress_factor() -> uint {
match os::getenv("RUST_TEST_STRESS") {

View file

@ -44,7 +44,7 @@ use core::mem;
use rustrt::local::Local;
use rustrt::task::{Task, BlockedTask};
use atomic;
use sync::atomic;
use comm::Receiver;
// Various states you can find a port in.

View file

@ -325,9 +325,9 @@ impl Iterator<*mut Handle<'static, ()>> for Packets {
#[cfg(test)]
#[allow(unused_imports)]
mod test {
use std::prelude::*;
use prelude::*;
use super::super::*;
use super::*;
// Don't use the libstd version so we can pull in the right Select structure
// (std::comm points at the wrong one)

View file

@ -30,8 +30,8 @@ use rustrt::mutex::NativeMutex;
use rustrt::task::{Task, BlockedTask};
use rustrt::thread::Thread;
use atomic;
use mpsc_queue as mpsc;
use sync::atomic;
use sync::mpsc_queue as mpsc;
const DISCONNECTED: int = int::MIN;
const FUDGE: int = 1024;

View file

@ -31,9 +31,9 @@ use rustrt::local::Local;
use rustrt::task::{Task, BlockedTask};
use rustrt::thread::Thread;
use atomic;
use sync::atomic;
use sync::spsc_queue as spsc;
use comm::Receiver;
use spsc_queue as spsc;
const DISCONNECTED: int = int::MIN;
#[cfg(test)]

View file

@ -39,14 +39,14 @@ pub use self::Failure::*;
use self::Blocker::*;
use alloc::boxed::Box;
use collections::Vec;
use vec::Vec;
use core::mem;
use core::cell::UnsafeCell;
use rustrt::local::Local;
use rustrt::mutex::{NativeMutex, LockGuard};
use rustrt::task::{Task, BlockedTask};
use atomic;
use sync::atomic;
pub struct Packet<T> {
/// Only field outside of the mutex. Just done for kicks, but mainly because

View file

@ -124,7 +124,6 @@ extern crate unicode;
extern crate core;
extern crate "collections" as core_collections;
extern crate "rand" as core_rand;
extern crate "sync" as core_sync;
extern crate libc;
extern crate rustrt;
@ -173,8 +172,6 @@ pub use rustrt::c_str;
pub use unicode::char;
pub use core_sync::comm;
/* Exported macros */
pub mod macros;
@ -236,6 +233,7 @@ pub mod hash;
pub mod task;
pub mod sync;
pub mod comm;
#[cfg(unix)]
#[path = "sys/unix/mod.rs"] mod sys;

View file

@ -178,7 +178,7 @@ impl<T: Send> Drop for AtomicOption<T> {
#[cfg(test)]
mod test {
use std::prelude::*;
use prelude::*;
use super::*;
#[test]

View file

@ -57,13 +57,13 @@ use core::prelude::*;
use alloc::arc::Arc;
use alloc::heap::{allocate, deallocate};
use alloc::boxed::Box;
use collections::Vec;
use vec::Vec;
use core::kinds::marker;
use core::mem::{forget, min_align_of, size_of, transmute};
use core::ptr;
use rustrt::exclusive::Exclusive;
use atomic::{AtomicInt, AtomicPtr, SeqCst};
use sync::atomic::{AtomicInt, AtomicPtr, SeqCst};
// Once the queue is less than 1/K full, then it will be downsized. Note that
// the deque requires that this number be less than 2.
@ -410,16 +410,16 @@ impl<T: Send> Drop for Buffer<T> {
#[cfg(test)]
mod tests {
use std::prelude::*;
use prelude::*;
use super::{Data, BufferPool, Abort, Empty, Worker, Stealer};
use std::mem;
use mem;
use rustrt::thread::Thread;
use std::rand;
use std::rand::Rng;
use atomic::{AtomicBool, INIT_ATOMIC_BOOL, SeqCst,
AtomicUint, INIT_ATOMIC_UINT};
use std::vec;
use rand;
use rand::Rng;
use sync::atomic::{AtomicBool, INIT_ATOMIC_BOOL, SeqCst,
AtomicUint, INIT_ATOMIC_UINT};
use vec;
#[test]
fn smoke() {

View file

@ -27,7 +27,7 @@ use core::cell::UnsafeCell;
use rustrt::local::Local;
use rustrt::task::Task;
use raw;
use super::raw;
/****************************************************************************
* Poisoning helpers
@ -158,7 +158,7 @@ impl<'a> Condvar<'a> {
/// # Example
///
/// ```
/// use sync::{Mutex, Arc};
/// use std::sync::{Mutex, Arc};
///
/// let mutex = Arc::new(Mutex::new(1i));
/// let mutex2 = mutex.clone();
@ -259,7 +259,7 @@ impl<'a, T: Send> DerefMut<T> for MutexGuard<'a, T> {
/// # Example
///
/// ```
/// use sync::{RWLock, Arc};
/// use std::sync::{RWLock, Arc};
///
/// let lock1 = Arc::new(RWLock::new(1i));
/// let lock2 = lock1.clone();
@ -395,7 +395,7 @@ impl<'a, T: Send + Sync> DerefMut<T> for RWLockWriteGuard<'a, T> {
/// of some computation.
///
/// ```rust
/// use sync::{Arc, Barrier};
/// use std::sync::{Arc, Barrier};
///
/// let barrier = Arc::new(Barrier::new(10));
/// for _ in range(0u, 10) {
@ -458,12 +458,12 @@ impl Barrier {
#[cfg(test)]
mod tests {
use std::prelude::*;
use std::comm::Empty;
use std::task;
use std::task::try_future;
use prelude::*;
use comm::Empty;
use task;
use task::try_future;
use sync::Arc;
use Arc;
use super::{Mutex, Barrier, RWLock};
#[test]

View file

@ -17,17 +17,41 @@
#![experimental]
#[stable]
pub use core_sync::atomic;
pub use self::one::{Once, ONCE_INIT};
pub use core_sync::{deque, mpmc_bounded_queue, mpsc_queue, spsc_queue};
pub use core_sync::{Arc, Weak, Mutex, MutexGuard, Condvar, Barrier};
pub use core_sync::{RWLock, RWLockReadGuard, RWLockWriteGuard};
pub use core_sync::{Semaphore, SemaphoreGuard};
pub use core_sync::one::{Once, ONCE_INIT};
pub use alloc::arc::{Arc, Weak};
pub use self::lock::{Mutex, MutexGuard, Condvar, Barrier,
RWLock, RWLockReadGuard, RWLockWriteGuard};
// The mutex/rwlock in this module are not meant for reexport
pub use self::raw::{Semaphore, SemaphoreGuard};
pub use self::future::Future;
pub use self::task_pool::TaskPool;
// Core building blocks for all primitives in this crate
#[stable]
pub mod atomic;
// Concurrent data structures
pub mod spsc_queue;
pub mod mpsc_queue;
pub mod mpmc_bounded_queue;
pub mod deque;
// Low-level concurrency primitives
mod raw;
mod mutex;
mod one;
// Higher level primitives based on those above
mod lock;
// Task management
mod future;
mod task_pool;

View file

@ -33,11 +33,11 @@
use core::prelude::*;
use alloc::arc::Arc;
use collections::Vec;
use vec::Vec;
use core::num::UnsignedInt;
use core::cell::UnsafeCell;
use atomic::{AtomicUint,Relaxed,Release,Acquire};
use sync::atomic::{AtomicUint,Relaxed,Release,Acquire};
struct Node<T> {
sequence: AtomicUint,
@ -165,7 +165,7 @@ impl<T: Send> Clone for Queue<T> {
#[cfg(test)]
mod tests {
use std::prelude::*;
use prelude::*;
use super::Queue;
#[test]

View file

@ -48,7 +48,7 @@ use alloc::boxed::Box;
use core::mem;
use core::cell::UnsafeCell;
use atomic::{AtomicPtr, Release, Acquire, AcqRel, Relaxed};
use sync::atomic::{AtomicPtr, Release, Acquire, AcqRel, Relaxed};
/// A result of the `pop` function.
pub enum PopResult<T> {
@ -159,7 +159,7 @@ impl<T: Send> Drop for Queue<T> {
#[cfg(test)]
mod tests {
use std::prelude::*;
use prelude::*;
use alloc::arc::Arc;

View file

@ -28,8 +28,8 @@ pub const BLOCKED: uint = 1 << 1;
///
/// # Example
///
/// ```rust
/// use sync::mutex::Mutex;
/// ```rust,ignore
/// use std::sync::mutex::Mutex;
///
/// let m = Mutex::new();
/// let guard = m.lock();
@ -57,8 +57,8 @@ pub struct Mutex {
///
/// # Example
///
/// ```rust
/// use sync::mutex::{StaticMutex, MUTEX_INIT};
/// ```rust,ignore
/// use std::sync::mutex::{StaticMutex, MUTEX_INIT};
///
/// static LOCK: StaticMutex = MUTEX_INIT;
///
@ -156,7 +156,7 @@ impl Drop for Mutex {
#[cfg(test)]
mod test {
use std::prelude::*;
use prelude::*;
use super::{Mutex, StaticMutex, MUTEX_INIT};
#[test]

View file

@ -18,7 +18,7 @@ use core::prelude::*;
use core::int;
use core::atomic;
use mutex::{StaticMutex, MUTEX_INIT};
use super::mutex::{StaticMutex, MUTEX_INIT};
/// A synchronization primitive which can be used to run a one-time global
/// initialization. Useful for one-time initialization for FFI or related
@ -27,8 +27,8 @@ use mutex::{StaticMutex, MUTEX_INIT};
///
/// # Example
///
/// ```rust
/// use sync::one::{Once, ONCE_INIT};
/// ```rust,ignore
/// use std::sync::one::{Once, ONCE_INIT};
///
/// static START: Once = ONCE_INIT;
///
@ -120,8 +120,8 @@ impl Once {
#[cfg(test)]
mod test {
use std::prelude::*;
use std::task;
use prelude::*;
use task;
use super::{ONCE_INIT, Once};
#[test]

View file

@ -15,6 +15,10 @@
//! `sync` crate which wrap values directly and provide safer abstractions for
//! containing data.
// A side-effect of merging libsync into libstd; will go away once
// libsync rewrite lands
#![allow(dead_code)]
use core::prelude::*;
use self::ReacquireOrderLock::*;
@ -23,9 +27,9 @@ use core::finally::Finally;
use core::kinds::marker;
use core::mem;
use core::cell::UnsafeCell;
use collections::Vec;
use vec::Vec;
use mutex;
use super::mutex;
use comm::{Receiver, Sender, channel};
/****************************************************************************
@ -518,8 +522,8 @@ impl RWLock {
///
/// # Example
///
/// ```rust
/// use sync::raw::RWLock;
/// ```{rust,ignore}
/// use std::sync::raw::RWLock;
///
/// let lock = RWLock::new();
/// let write = lock.write();
@ -622,14 +626,13 @@ impl<'a> Drop for RWLockReadGuard<'a> {
mod tests {
pub use self::RWLockMode::*;
use std::prelude::*;
use Arc;
use sync::Arc;
use prelude::*;
use super::{Semaphore, Mutex, RWLock, Condvar};
use std::mem;
use std::result;
use std::task;
use mem;
use result;
use task;
/************************************************************************
* Semaphore tests
@ -837,7 +840,7 @@ mod tests {
}
#[test]
fn test_mutex_killed_simple() {
use std::any::Any;
use any::Any;
// Mutex must get automatically unlocked if panicked/killed within.
let m = Arc::new(Mutex::new());
@ -1077,7 +1080,7 @@ mod tests {
}
#[cfg(test)]
fn rwlock_kill_helper(mode1: RWLockMode, mode2: RWLockMode) {
use std::any::Any;
use any::Any;
// Mutex must get automatically unlocked if panicked/killed within.
let x = Arc::new(RWLock::new());

View file

@ -42,7 +42,7 @@ use core::mem;
use core::cell::UnsafeCell;
use alloc::arc::Arc;
use atomic::{AtomicPtr, Relaxed, AtomicUint, Acquire, Release};
use sync::atomic::{AtomicPtr, Relaxed, AtomicUint, Acquire, Release};
// Node within the linked list queue of messages to send
struct Node<T> {
@ -294,7 +294,7 @@ impl<T: Send> Drop for Queue<T> {
#[cfg(test)]
mod test {
use std::prelude::*;
use prelude::*;
use super::{queue};

View file

@ -1,78 +0,0 @@
// 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 <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.
//! Core concurrency-enabled mechanisms and primitives.
//!
//! This crate contains the implementations of Rust's core synchronization
//! primitives. This includes channels, mutexes, condition variables, etc.
//!
//! The interface of this crate is experimental, and it is not recommended to
//! use this crate specifically. Instead, its functionality is reexported
//! through `std::sync`.
#![crate_name = "sync"]
#![experimental]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![license = "MIT/ASL2"]
#![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/nightly/",
html_playground_url = "http://play.rust-lang.org/")]
#![feature(phase, globs, macro_rules, unsafe_destructor)]
#![feature(import_shadowing)]
#![deny(missing_docs)]
#![no_std]
#[phase(plugin, link)] extern crate core;
extern crate alloc;
extern crate collections;
extern crate rustrt;
#[cfg(test)] extern crate test;
#[cfg(test)] #[phase(plugin, link)] extern crate std;
pub use alloc::arc::{Arc, Weak};
pub use lock::{Mutex, MutexGuard, Condvar, Barrier,
RWLock, RWLockReadGuard, RWLockWriteGuard};
// The mutex/rwlock in this module are not meant for reexport
pub use raw::{Semaphore, SemaphoreGuard};
// Core building blocks for all primitives in this crate
pub mod atomic;
// Concurrent data structures
pub mod spsc_queue;
pub mod mpsc_queue;
pub mod mpmc_bounded_queue;
pub mod deque;
// Low-level concurrency primitives
pub mod raw;
pub mod mutex;
pub mod one;
// Message-passing based communication
pub mod comm;
// Higher level primitives based on those above
mod lock;
#[cfg(not(test))]
mod std {
pub use core::{fmt, option, cmp, clone};
}