Skip to content

Commit

Permalink
Merge libsync into libstd
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aturon committed Nov 24, 2014
1 parent 54c628c commit 985acfd
Show file tree
Hide file tree
Showing 20 changed files with 103 additions and 159 deletions.
5 changes: 2 additions & 3 deletions mk/crates.mk
Expand Up @@ -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 \
Expand All @@ -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
Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/etc/licenseck.py
Expand Up @@ -38,10 +38,9 @@
"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
Expand Down
13 changes: 6 additions & 7 deletions src/libsync/comm/mod.rs → src/libstd/comm/mod.rs
Expand Up @@ -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 }
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/comm/oneshot.rs → src/libstd/comm/oneshot.rs
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/comm/select.rs → src/libstd/comm/select.rs
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/comm/shared.rs → src/libstd/comm/shared.rs
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/comm/stream.rs → src/libstd/comm/stream.rs
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/comm/sync.rs → src/libstd/comm/sync.rs
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/libstd/lib.rs
Expand Up @@ -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;

Expand Down Expand Up @@ -173,8 +172,6 @@ pub use rustrt::c_str;

pub use unicode::char;

pub use core_sync::comm;

/* Exported macros */

pub mod macros;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/atomic.rs → src/libstd/sync/atomic.rs
Expand Up @@ -178,7 +178,7 @@ impl<T: Send> Drop for AtomicOption<T> {

#[cfg(test)]
mod test {
use std::prelude::*;
use prelude::*;
use super::*;

#[test]
Expand Down
18 changes: 9 additions & 9 deletions src/libsync/deque.rs → src/libstd/sync/deque.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down
18 changes: 9 additions & 9 deletions src/libsync/lock.rs → src/libstd/sync/lock.rs
Expand Up @@ -27,7 +27,7 @@ use core::cell::UnsafeCell;
use rustrt::local::Local;
use rustrt::task::Task;

use raw;
use super::raw;

/****************************************************************************
* Poisoning helpers
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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]
Expand Down
38 changes: 31 additions & 7 deletions src/libstd/sync/mod.rs
Expand Up @@ -17,17 +17,41 @@

#![experimental]

#[stable]
pub use core_sync::atomic;
pub use self::one::{Once, ONCE_INIT};

pub use alloc::arc::{Arc, Weak};
pub use self::lock::{Mutex, MutexGuard, Condvar, Barrier,
RWLock, RWLockReadGuard, RWLockWriteGuard};

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};
// 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;
Expand Up @@ -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,
Expand Down Expand Up @@ -165,7 +165,7 @@ impl<T: Send> Clone for Queue<T> {

#[cfg(test)]
mod tests {
use std::prelude::*;
use prelude::*;
use super::Queue;

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/mpsc_queue.rs → src/libstd/sync/mpsc_queue.rs
Expand Up @@ -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> {
Expand Down Expand Up @@ -159,7 +159,7 @@ impl<T: Send> Drop for Queue<T> {

#[cfg(test)]
mod tests {
use std::prelude::*;
use prelude::*;

use alloc::arc::Arc;

Expand Down
10 changes: 5 additions & 5 deletions src/libsync/mutex.rs → src/libstd/sync/mutex.rs
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
///
Expand Down Expand Up @@ -156,7 +156,7 @@ impl Drop for Mutex {

#[cfg(test)]
mod test {
use std::prelude::*;
use prelude::*;
use super::{Mutex, StaticMutex, MUTEX_INIT};

#[test]
Expand Down

9 comments on commit 985acfd

@bors
Copy link
Contributor

@bors bors commented on 985acfd Nov 25, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton, alexcrichton
at aturon@985acfd

@bors
Copy link
Contributor

@bors bors commented on 985acfd Nov 25, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging aturon/rust/merge-sync = 985acfd into auto

@bors
Copy link
Contributor

@bors bors commented on 985acfd Nov 25, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aturon/rust/merge-sync = 985acfd merged ok, testing candidate = a084689

@bors
Copy link
Contributor

@bors bors commented on 985acfd Nov 25, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 985acfd Nov 25, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton, alexcrichton
at aturon@985acfd

@bors
Copy link
Contributor

@bors bors commented on 985acfd Nov 25, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging aturon/rust/merge-sync = 985acfd into auto

@bors
Copy link
Contributor

@bors bors commented on 985acfd Nov 25, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aturon/rust/merge-sync = 985acfd merged ok, testing candidate = 689ef2d

@bors
Copy link
Contributor

@bors bors commented on 985acfd Nov 25, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 985acfd Nov 25, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 689ef2d

Please sign in to comment.