Skip to content

Commit 689ef2d

Browse files
committed
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
2 parents 0e06f71 + 985acfd commit 689ef2d

20 files changed

+103
-159
lines changed

mk/crates.mk

+2-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
################################################################################
5151

5252
TARGET_CRATES := libc std flate arena term \
53-
serialize sync getopts collections test time rand \
53+
serialize getopts collections test time rand \
5454
log regex graphviz core rbml alloc rustrt \
5555
unicode
5656
HOST_CRATES := syntax rustc rustc_trans rustdoc regex_macros fmt_macros \
@@ -63,7 +63,7 @@ DEPS_libc := core
6363
DEPS_unicode := core
6464
DEPS_alloc := core libc native:jemalloc
6565
DEPS_rustrt := alloc core libc collections native:rustrt_native
66-
DEPS_std := core libc rand alloc collections rustrt sync unicode \
66+
DEPS_std := core libc rand alloc collections rustrt unicode \
6767
native:rust_builtin native:backtrace
6868
DEPS_graphviz := std
6969
DEPS_syntax := std term serialize log fmt_macros arena libc
@@ -81,7 +81,6 @@ DEPS_glob := std
8181
DEPS_serialize := std log
8282
DEPS_rbml := std log serialize
8383
DEPS_term := std log
84-
DEPS_sync := core alloc rustrt collections
8584
DEPS_getopts := std
8685
DEPS_collections := core alloc unicode
8786
DEPS_num := std

src/etc/licenseck.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@
3838
"rt/isaac/randport.cpp", # public domain
3939
"rt/isaac/rand.h", # public domain
4040
"rt/isaac/standard.h", # public domain
41-
"libsync/mpsc_queue.rs", # BSD
42-
"libsync/spsc_queue.rs", # BSD
43-
"libsync/mpmc_bounded_queue.rs", # BSD
44-
"libsync/mpsc_intrusive.rs", # BSD
41+
"libstd/sync/mpsc_queue.rs", # BSD
42+
"libstd/sync/spsc_queue.rs", # BSD
43+
"libstd/sync/mpmc_bounded_queue.rs", # BSD
4544
"test/bench/shootout-binarytrees.rs", # BSD
4645
"test/bench/shootout-chameneos-redux.rs", # BSD
4746
"test/bench/shootout-fannkuch-redux.rs", # BSD

src/libsync/comm/mod.rs src/libstd/comm/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,11 @@ macro_rules! test (
338338

339339
extern crate rustrt;
340340

341-
use std::prelude::*;
341+
use prelude::*;
342342

343343
use comm::*;
344344
use super::*;
345-
use super::super::*;
346-
use std::task;
345+
use task;
347346

348347
$(#[$a])* #[test] fn f() { $b }
349348
}
@@ -1019,9 +1018,9 @@ impl<T: Send> Drop for Receiver<T> {
10191018

10201019
#[cfg(test)]
10211020
mod test {
1022-
use std::prelude::*;
1021+
use prelude::*;
10231022

1024-
use std::os;
1023+
use os;
10251024
use super::*;
10261025

10271026
pub fn stress_factor() -> uint {
@@ -1554,8 +1553,8 @@ mod test {
15541553

15551554
#[cfg(test)]
15561555
mod sync_tests {
1557-
use std::prelude::*;
1558-
use std::os;
1556+
use prelude::*;
1557+
use os;
15591558

15601559
pub fn stress_factor() -> uint {
15611560
match os::getenv("RUST_TEST_STRESS") {

src/libsync/comm/oneshot.rs src/libstd/comm/oneshot.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use core::mem;
4444
use rustrt::local::Local;
4545
use rustrt::task::{Task, BlockedTask};
4646

47-
use atomic;
47+
use sync::atomic;
4848
use comm::Receiver;
4949

5050
// Various states you can find a port in.

src/libsync/comm/select.rs src/libstd/comm/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,9 @@ impl Iterator<*mut Handle<'static, ()>> for Packets {
325325
#[cfg(test)]
326326
#[allow(unused_imports)]
327327
mod test {
328-
use std::prelude::*;
328+
use prelude::*;
329329

330-
use super::super::*;
330+
use super::*;
331331

332332
// Don't use the libstd version so we can pull in the right Select structure
333333
// (std::comm points at the wrong one)

src/libsync/comm/shared.rs src/libstd/comm/shared.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use rustrt::mutex::NativeMutex;
3030
use rustrt::task::{Task, BlockedTask};
3131
use rustrt::thread::Thread;
3232

33-
use atomic;
34-
use mpsc_queue as mpsc;
33+
use sync::atomic;
34+
use sync::mpsc_queue as mpsc;
3535

3636
const DISCONNECTED: int = int::MIN;
3737
const FUDGE: int = 1024;

src/libsync/comm/stream.rs src/libstd/comm/stream.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ use rustrt::local::Local;
3131
use rustrt::task::{Task, BlockedTask};
3232
use rustrt::thread::Thread;
3333

34-
use atomic;
34+
use sync::atomic;
35+
use sync::spsc_queue as spsc;
3536
use comm::Receiver;
36-
use spsc_queue as spsc;
3737

3838
const DISCONNECTED: int = int::MIN;
3939
#[cfg(test)]

src/libsync/comm/sync.rs src/libstd/comm/sync.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ pub use self::Failure::*;
3939
use self::Blocker::*;
4040

4141
use alloc::boxed::Box;
42-
use collections::Vec;
42+
use vec::Vec;
4343
use core::mem;
4444
use core::cell::UnsafeCell;
4545
use rustrt::local::Local;
4646
use rustrt::mutex::{NativeMutex, LockGuard};
4747
use rustrt::task::{Task, BlockedTask};
4848

49-
use atomic;
49+
use sync::atomic;
5050

5151
pub struct Packet<T> {
5252
/// Only field outside of the mutex. Just done for kicks, but mainly because

src/libstd/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ extern crate unicode;
124124
extern crate core;
125125
extern crate "collections" as core_collections;
126126
extern crate "rand" as core_rand;
127-
extern crate "sync" as core_sync;
128127
extern crate libc;
129128
extern crate rustrt;
130129

@@ -173,8 +172,6 @@ pub use rustrt::c_str;
173172

174173
pub use unicode::char;
175174

176-
pub use core_sync::comm;
177-
178175
/* Exported macros */
179176

180177
pub mod macros;
@@ -236,6 +233,7 @@ pub mod hash;
236233

237234
pub mod task;
238235
pub mod sync;
236+
pub mod comm;
239237

240238
#[cfg(unix)]
241239
#[path = "sys/unix/mod.rs"] mod sys;

src/libsync/atomic.rs src/libstd/sync/atomic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<T: Send> Drop for AtomicOption<T> {
178178

179179
#[cfg(test)]
180180
mod test {
181-
use std::prelude::*;
181+
use prelude::*;
182182
use super::*;
183183

184184
#[test]

src/libsync/deque.rs src/libstd/sync/deque.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ use core::prelude::*;
5757
use alloc::arc::Arc;
5858
use alloc::heap::{allocate, deallocate};
5959
use alloc::boxed::Box;
60-
use collections::Vec;
60+
use vec::Vec;
6161
use core::kinds::marker;
6262
use core::mem::{forget, min_align_of, size_of, transmute};
6363
use core::ptr;
6464
use rustrt::exclusive::Exclusive;
6565

66-
use atomic::{AtomicInt, AtomicPtr, SeqCst};
66+
use sync::atomic::{AtomicInt, AtomicPtr, SeqCst};
6767

6868
// Once the queue is less than 1/K full, then it will be downsized. Note that
6969
// the deque requires that this number be less than 2.
@@ -410,16 +410,16 @@ impl<T: Send> Drop for Buffer<T> {
410410

411411
#[cfg(test)]
412412
mod tests {
413-
use std::prelude::*;
413+
use prelude::*;
414414
use super::{Data, BufferPool, Abort, Empty, Worker, Stealer};
415415

416-
use std::mem;
416+
use mem;
417417
use rustrt::thread::Thread;
418-
use std::rand;
419-
use std::rand::Rng;
420-
use atomic::{AtomicBool, INIT_ATOMIC_BOOL, SeqCst,
421-
AtomicUint, INIT_ATOMIC_UINT};
422-
use std::vec;
418+
use rand;
419+
use rand::Rng;
420+
use sync::atomic::{AtomicBool, INIT_ATOMIC_BOOL, SeqCst,
421+
AtomicUint, INIT_ATOMIC_UINT};
422+
use vec;
423423

424424
#[test]
425425
fn smoke() {

src/libsync/lock.rs src/libstd/sync/lock.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use core::cell::UnsafeCell;
2727
use rustrt::local::Local;
2828
use rustrt::task::Task;
2929

30-
use raw;
30+
use super::raw;
3131

3232
/****************************************************************************
3333
* Poisoning helpers
@@ -158,7 +158,7 @@ impl<'a> Condvar<'a> {
158158
/// # Example
159159
///
160160
/// ```
161-
/// use sync::{Mutex, Arc};
161+
/// use std::sync::{Mutex, Arc};
162162
///
163163
/// let mutex = Arc::new(Mutex::new(1i));
164164
/// let mutex2 = mutex.clone();
@@ -259,7 +259,7 @@ impl<'a, T: Send> DerefMut<T> for MutexGuard<'a, T> {
259259
/// # Example
260260
///
261261
/// ```
262-
/// use sync::{RWLock, Arc};
262+
/// use std::sync::{RWLock, Arc};
263263
///
264264
/// let lock1 = Arc::new(RWLock::new(1i));
265265
/// let lock2 = lock1.clone();
@@ -395,7 +395,7 @@ impl<'a, T: Send + Sync> DerefMut<T> for RWLockWriteGuard<'a, T> {
395395
/// of some computation.
396396
///
397397
/// ```rust
398-
/// use sync::{Arc, Barrier};
398+
/// use std::sync::{Arc, Barrier};
399399
///
400400
/// let barrier = Arc::new(Barrier::new(10));
401401
/// for _ in range(0u, 10) {
@@ -458,12 +458,12 @@ impl Barrier {
458458

459459
#[cfg(test)]
460460
mod tests {
461-
use std::prelude::*;
462-
use std::comm::Empty;
463-
use std::task;
464-
use std::task::try_future;
461+
use prelude::*;
462+
use comm::Empty;
463+
use task;
464+
use task::try_future;
465+
use sync::Arc;
465466

466-
use Arc;
467467
use super::{Mutex, Barrier, RWLock};
468468

469469
#[test]

src/libstd/sync/mod.rs

+31-7
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,41 @@
1717
1818
#![experimental]
1919

20-
#[stable]
21-
pub use core_sync::atomic;
20+
pub use self::one::{Once, ONCE_INIT};
21+
22+
pub use alloc::arc::{Arc, Weak};
23+
pub use self::lock::{Mutex, MutexGuard, Condvar, Barrier,
24+
RWLock, RWLockReadGuard, RWLockWriteGuard};
2225

23-
pub use core_sync::{deque, mpmc_bounded_queue, mpsc_queue, spsc_queue};
24-
pub use core_sync::{Arc, Weak, Mutex, MutexGuard, Condvar, Barrier};
25-
pub use core_sync::{RWLock, RWLockReadGuard, RWLockWriteGuard};
26-
pub use core_sync::{Semaphore, SemaphoreGuard};
27-
pub use core_sync::one::{Once, ONCE_INIT};
26+
// The mutex/rwlock in this module are not meant for reexport
27+
pub use self::raw::{Semaphore, SemaphoreGuard};
2828

2929
pub use self::future::Future;
3030
pub use self::task_pool::TaskPool;
3131

32+
// Core building blocks for all primitives in this crate
33+
34+
#[stable]
35+
pub mod atomic;
36+
37+
// Concurrent data structures
38+
39+
pub mod spsc_queue;
40+
pub mod mpsc_queue;
41+
pub mod mpmc_bounded_queue;
42+
pub mod deque;
43+
44+
// Low-level concurrency primitives
45+
46+
mod raw;
47+
mod mutex;
48+
mod one;
49+
50+
// Higher level primitives based on those above
51+
52+
mod lock;
53+
54+
// Task management
55+
3256
mod future;
3357
mod task_pool;

src/libsync/mpmc_bounded_queue.rs src/libstd/sync/mpmc_bounded_queue.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
use core::prelude::*;
3434

3535
use alloc::arc::Arc;
36-
use collections::Vec;
36+
use vec::Vec;
3737
use core::num::UnsignedInt;
3838
use core::cell::UnsafeCell;
3939

40-
use atomic::{AtomicUint,Relaxed,Release,Acquire};
40+
use sync::atomic::{AtomicUint,Relaxed,Release,Acquire};
4141

4242
struct Node<T> {
4343
sequence: AtomicUint,
@@ -165,7 +165,7 @@ impl<T: Send> Clone for Queue<T> {
165165

166166
#[cfg(test)]
167167
mod tests {
168-
use std::prelude::*;
168+
use prelude::*;
169169
use super::Queue;
170170

171171
#[test]

src/libsync/mpsc_queue.rs src/libstd/sync/mpsc_queue.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use alloc::boxed::Box;
4848
use core::mem;
4949
use core::cell::UnsafeCell;
5050

51-
use atomic::{AtomicPtr, Release, Acquire, AcqRel, Relaxed};
51+
use sync::atomic::{AtomicPtr, Release, Acquire, AcqRel, Relaxed};
5252

5353
/// A result of the `pop` function.
5454
pub enum PopResult<T> {
@@ -159,7 +159,7 @@ impl<T: Send> Drop for Queue<T> {
159159

160160
#[cfg(test)]
161161
mod tests {
162-
use std::prelude::*;
162+
use prelude::*;
163163

164164
use alloc::arc::Arc;
165165

src/libsync/mutex.rs src/libstd/sync/mutex.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ pub const BLOCKED: uint = 1 << 1;
2828
///
2929
/// # Example
3030
///
31-
/// ```rust
32-
/// use sync::mutex::Mutex;
31+
/// ```rust,ignore
32+
/// use std::sync::mutex::Mutex;
3333
///
3434
/// let m = Mutex::new();
3535
/// let guard = m.lock();
@@ -57,8 +57,8 @@ pub struct Mutex {
5757
///
5858
/// # Example
5959
///
60-
/// ```rust
61-
/// use sync::mutex::{StaticMutex, MUTEX_INIT};
60+
/// ```rust,ignore
61+
/// use std::sync::mutex::{StaticMutex, MUTEX_INIT};
6262
///
6363
/// static LOCK: StaticMutex = MUTEX_INIT;
6464
///
@@ -156,7 +156,7 @@ impl Drop for Mutex {
156156

157157
#[cfg(test)]
158158
mod test {
159-
use std::prelude::*;
159+
use prelude::*;
160160
use super::{Mutex, StaticMutex, MUTEX_INIT};
161161

162162
#[test]

0 commit comments

Comments
 (0)