Merge libsync into libstd

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.
This commit is contained in:
Aaron Turon
2014-11-23 12:52:37 -08:00
parent 54c628cb84
commit 985acfdb67
20 changed files with 103 additions and 159 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -39,14 +39,14 @@ pub use self::Failure::*;
use self::Blocker::*; use self::Blocker::*;
use alloc::boxed::Box; use alloc::boxed::Box;
use collections::Vec; use vec::Vec;
use core::mem; use core::mem;
use core::cell::UnsafeCell; use core::cell::UnsafeCell;
use rustrt::local::Local; use rustrt::local::Local;
use rustrt::mutex::{NativeMutex, LockGuard}; use rustrt::mutex::{NativeMutex, LockGuard};
use rustrt::task::{Task, BlockedTask}; use rustrt::task::{Task, BlockedTask};
use atomic; use sync::atomic;
pub struct Packet<T> { pub struct Packet<T> {
/// Only field outside of the mutex. Just done for kicks, but mainly because /// 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 core;
extern crate "collections" as core_collections; extern crate "collections" as core_collections;
extern crate "rand" as core_rand; extern crate "rand" as core_rand;
extern crate "sync" as core_sync;
extern crate libc; extern crate libc;
extern crate rustrt; extern crate rustrt;
@@ -173,8 +172,6 @@ pub use rustrt::c_str;
pub use unicode::char; pub use unicode::char;
pub use core_sync::comm;
/* Exported macros */ /* Exported macros */
pub mod macros; pub mod macros;
@@ -236,6 +233,7 @@ pub mod hash;
pub mod task; pub mod task;
pub mod sync; pub mod sync;
pub mod comm;
#[cfg(unix)] #[cfg(unix)]
#[path = "sys/unix/mod.rs"] mod sys; #[path = "sys/unix/mod.rs"] mod sys;

View File

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

View File

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

View File

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

View File

@@ -17,17 +17,41 @@
#![experimental] #![experimental]
#[stable] pub use self::one::{Once, ONCE_INIT};
pub use core_sync::atomic;
pub use core_sync::{deque, mpmc_bounded_queue, mpsc_queue, spsc_queue}; pub use alloc::arc::{Arc, Weak};
pub use core_sync::{Arc, Weak, Mutex, MutexGuard, Condvar, Barrier}; pub use self::lock::{Mutex, MutexGuard, Condvar, Barrier,
pub use core_sync::{RWLock, RWLockReadGuard, RWLockWriteGuard}; RWLock, RWLockReadGuard, RWLockWriteGuard};
pub use core_sync::{Semaphore, SemaphoreGuard};
pub use core_sync::one::{Once, ONCE_INIT}; // 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::future::Future;
pub use self::task_pool::TaskPool; 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 future;
mod task_pool; mod task_pool;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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