Skip to content

Commit f3a7ec7

Browse files
committed
std: Second pass stabilization of sync
This pass performs a second pass of stabilization through the `std::sync` module, avoiding modules/types that are being handled in other PRs (e.g. mutexes, rwlocks, condvars, and channels). The following items are now stable * `sync::atomic` * `sync::atomic::ATOMIC_BOOL_INIT` (was `INIT_ATOMIC_BOOL`) * `sync::atomic::ATOMIC_INT_INIT` (was `INIT_ATOMIC_INT`) * `sync::atomic::ATOMIC_UINT_INIT` (was `INIT_ATOMIC_UINT`) * `sync::Once` * `sync::ONCE_INIT` * `sync::Once::call_once` (was `doit`) * C == `pthread_once(..)` * Boost == `call_once(..)` * Windows == `InitOnceExecuteOnce` * `sync::Barrier` * `sync::Barrier::new` * `sync::Barrier::wait` (now returns a `bool`) * `sync::Semaphore::new` * `sync::Semaphore::acquire` * `sync::Semaphore::release` The following items remain unstable * `sync::SemaphoreGuard` * `sync::Semaphore::access` - it's unclear how this relates to the poisoning story of mutexes. * `sync::TaskPool` - the semantics of a failing task and whether a thread is re-attached to a thread pool are somewhat unclear, and the utility of this type in `sync` is question with respect to the jobs of other primitives. This type will likely become stable or move out of the standard library over time. * `sync::Future` - futures as-is have yet to be deeply re-evaluated with the recent core changes to Rust's synchronization story, and will likely become stable in the future but are unstable until that time comes. [breaking-change]
1 parent cd61416 commit f3a7ec7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+168
-237
lines changed

src/doc/guide-tasks.md

+2
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ getting the result later.
206206
The basic example below illustrates this.
207207

208208
```{rust,ignore}
209+
# #![allow(deprecated)]
209210
use std::sync::Future;
210211
211212
# fn main() {
@@ -233,6 +234,7 @@ Here is another example showing how futures allow you to background
233234
computations. The workload will be distributed on the available cores.
234235

235236
```{rust,ignore}
237+
# #![allow(deprecated)]
236238
# use std::num::Float;
237239
# use std::sync::Future;
238240
fn partial_sum(start: uint) -> f64 {

src/doc/guide.md

+1
Original file line numberDiff line numberDiff line change
@@ -5312,6 +5312,7 @@ example, if you wish to compute some value in the background, `Future` is
53125312
a useful thing to use:
53135313
53145314
```{rust}
5315+
# #![allow(deprecated)]
53155316
use std::sync::Future;
53165317
53175318
let mut delayed_value = Future::spawn(move || {

src/doc/reference.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1480,9 +1480,9 @@ data are being stored, or single-address and mutability properties are required.
14801480
```
14811481
use std::sync::atomic;
14821482
1483-
// Note that INIT_ATOMIC_UINT is a *const*, but it may be used to initialize a
1483+
// Note that ATOMIC_UINT_INIT is a *const*, but it may be used to initialize a
14841484
// static. This static can be modified, so it is not placed in read-only memory.
1485-
static COUNTER: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
1485+
static COUNTER: atomic::AtomicUint = atomic::ATOMIC_UINT_INIT;
14861486
14871487
// This table is a candidate to be placed in read-only memory.
14881488
static TABLE: &'static [uint] = &[1, 2, 3, /* ... */];

src/libcollections/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,7 @@ mod tests {
22632263
}
22642264
}
22652265
const NUM_ELEMENTS: uint = 2;
2266-
static DROP_COUNTER: AtomicUint = atomic::INIT_ATOMIC_UINT;
2266+
static DROP_COUNTER: AtomicUint = atomic::ATOMIC_UINT_INIT;
22672267

22682268
let v = Vec::from_elem(NUM_ELEMENTS, Nothing);
22692269

src/libcore/atomic.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,27 @@ pub enum Ordering {
8989

9090
/// An `AtomicBool` initialized to `false`.
9191
#[unstable = "may be renamed, pending conventions for static initalizers"]
92-
pub const INIT_ATOMIC_BOOL: AtomicBool =
92+
pub const ATOMIC_BOOL_INIT: AtomicBool =
9393
AtomicBool { v: UnsafeCell { value: 0 } };
9494
/// An `AtomicInt` initialized to `0`.
9595
#[unstable = "may be renamed, pending conventions for static initalizers"]
96-
pub const INIT_ATOMIC_INT: AtomicInt =
96+
pub const ATOMIC_INT_INIT: AtomicInt =
9797
AtomicInt { v: UnsafeCell { value: 0 } };
9898
/// An `AtomicUint` initialized to `0`.
9999
#[unstable = "may be renamed, pending conventions for static initalizers"]
100-
pub const INIT_ATOMIC_UINT: AtomicUint =
100+
pub const ATOMIC_UINT_INIT: AtomicUint =
101101
AtomicUint { v: UnsafeCell { value: 0, } };
102102

103+
/// Deprecated
104+
#[deprecated = "renamed to ATOMIC_BOOL_INIT"]
105+
pub const INIT_ATOMIC_BOOL: AtomicBool = ATOMIC_BOOL_INIT;
106+
/// Deprecated
107+
#[deprecated = "renamed to ATOMIC_INT_INIT"]
108+
pub const INIT_ATOMIC_INT: AtomicInt = ATOMIC_INT_INIT;
109+
/// Deprecated
110+
#[deprecated = "renamed to ATOMIC_UINT_INIT"]
111+
pub const INIT_ATOMIC_UINT: AtomicUint = ATOMIC_UINT_INIT;
112+
103113
// NB: Needs to be -1 (0b11111111...) to make fetch_nand work correctly
104114
const UINT_TRUE: uint = -1;
105115

src/libcore/cell.rs

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@
155155
// FIXME: Can't be shared between threads. Dynamic borrows
156156
// FIXME: Relationship to Atomic types and RWLock
157157

158+
#![stable]
159+
158160
use clone::Clone;
159161
use cmp::PartialEq;
160162
use default::Default;

src/libcoretest/atomic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ fn int_xor() {
7070
assert_eq!(x.load(SeqCst), 0xf731 ^ 0x137f);
7171
}
7272

73-
static S_BOOL : AtomicBool = INIT_ATOMIC_BOOL;
74-
static S_INT : AtomicInt = INIT_ATOMIC_INT;
75-
static S_UINT : AtomicUint = INIT_ATOMIC_UINT;
73+
static S_BOOL : AtomicBool = ATOMIC_BOOL_INIT;
74+
static S_INT : AtomicInt = ATOMIC_INT_INIT;
75+
static S_UINT : AtomicUint = ATOMIC_UINT_INIT;
7676

7777
#[test]
7878
fn static_init() {

src/liblog/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ pub struct LogLocation {
352352
#[doc(hidden)]
353353
pub fn mod_enabled(level: u32, module: &str) -> bool {
354354
static INIT: Once = ONCE_INIT;
355-
INIT.doit(init);
355+
INIT.call_once(init);
356356

357357
// It's possible for many threads are in this function, only one of them
358358
// will perform the global initialization, but all of them will need to check

src/librustc/middle/infer/region_inference/graphviz.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub fn maybe_print_constraints_for<'a, 'tcx>(region_vars: &RegionVarBindings<'a,
7373
let output_path = {
7474
let output_template = match requested_output {
7575
Some(ref s) if s.as_slice() == "help" => {
76-
static PRINTED_YET : atomic::AtomicBool = atomic::INIT_ATOMIC_BOOL;
76+
static PRINTED_YET : atomic::AtomicBool = atomic::ATOMIC_BOOL_INIT;
7777
if !PRINTED_YET.load(atomic::SeqCst) {
7878
print_help_message();
7979
PRINTED_YET.store(true, atomic::SeqCst);

src/librustc_trans/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ unsafe fn configure_llvm(sess: &Session) {
10091009
}
10101010
}
10111011

1012-
INIT.doit(|| {
1012+
INIT.call_once(|| {
10131013
llvm::LLVMInitializePasses();
10141014

10151015
// Only initialize the platforms supported by Rust here, because

src/librustc_trans/trans/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3097,7 +3097,7 @@ pub fn trans_crate<'tcx>(analysis: ty::CrateAnalysis<'tcx>)
30973097
use std::sync::{Once, ONCE_INIT};
30983098
static INIT: Once = ONCE_INIT;
30993099
static mut POISONED: bool = false;
3100-
INIT.doit(|| {
3100+
INIT.call_once(|| {
31013101
if llvm::LLVMStartMultithreaded() != 1 {
31023102
// use an extra bool to make sure that all future usage of LLVM
31033103
// cannot proceed despite the Once not running more than once.

src/libstd/comm/blocking.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! Generic support for building blocking abstractions.
1212
1313
use thread::Thread;
14-
use sync::atomic::{AtomicBool, INIT_ATOMIC_BOOL, Ordering};
14+
use sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
1515
use sync::Arc;
1616
use kinds::{Sync, Send};
1717
use kinds::marker::{NoSend, NoSync};
@@ -40,7 +40,7 @@ pub struct WaitToken {
4040
pub fn tokens() -> (WaitToken, SignalToken) {
4141
let inner = Arc::new(Inner {
4242
thread: Thread::current(),
43-
woken: INIT_ATOMIC_BOOL,
43+
woken: ATOMIC_BOOL_INIT,
4444
});
4545
let wait_token = WaitToken {
4646
inner: inner.clone(),

src/libstd/io/buffered.rs

-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use result::Result::{Ok, Err};
2222
use slice::{SliceExt};
2323
use slice;
2424
use vec::Vec;
25-
use kinds::{Send,Sync};
2625

2726
/// Wraps a Reader and buffers input from it
2827
///
@@ -52,11 +51,6 @@ pub struct BufferedReader<R> {
5251
cap: uint,
5352
}
5453

55-
56-
unsafe impl<R: Send> Send for BufferedReader<R> {}
57-
unsafe impl<R: Send+Sync> Sync for BufferedReader<R> {}
58-
59-
6054
impl<R: Reader> BufferedReader<R> {
6155
/// Creates a new `BufferedReader` with the specified buffer capacity
6256
pub fn with_capacity(cap: uint, inner: R) -> BufferedReader<R> {

src/libstd/io/stdio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub fn stdin() -> StdinReader {
218218
static ONCE: Once = ONCE_INIT;
219219

220220
unsafe {
221-
ONCE.doit(|| {
221+
ONCE.call_once(|| {
222222
// The default buffer capacity is 64k, but apparently windows doesn't like
223223
// 64k reads on stdin. See #13304 for details, but the idea is that on
224224
// windows we use a slightly smaller buffer that's been seen to be

src/libstd/io/tempfile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl TempDir {
9090
return TempDir::new_in(&abs_tmpdir, suffix);
9191
}
9292

93-
static CNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
93+
static CNT: atomic::AtomicUint = atomic::ATOMIC_UINT_INIT;
9494

9595
let mut attempts = 0u;
9696
loop {

src/libstd/io/test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ use libc;
1616
use os;
1717
use prelude::*;
1818
use std::io::net::ip::*;
19-
use sync::atomic::{AtomicUint, INIT_ATOMIC_UINT, Relaxed};
19+
use sync::atomic::{AtomicUint, ATOMIC_UINT_INIT, Relaxed};
2020

2121
/// Get a port number, starting at 9600, for use in tests
2222
pub fn next_test_port() -> u16 {
23-
static NEXT_OFFSET: AtomicUint = INIT_ATOMIC_UINT;
23+
static NEXT_OFFSET: AtomicUint = ATOMIC_UINT_INIT;
2424
base_port() + NEXT_OFFSET.fetch_add(1, Relaxed) as u16
2525
}
2626

2727
/// Get a temporary path which could be the location of a unix socket
2828
pub fn next_test_unix() -> Path {
29-
static COUNT: AtomicUint = INIT_ATOMIC_UINT;
29+
static COUNT: AtomicUint = ATOMIC_UINT_INIT;
3030
// base port and pid are an attempt to be unique between multiple
3131
// test-runners of different configurations running on one
3232
// buildbot, the count is to be unique within this executable.

src/libstd/os.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use slice::{AsSlice, SliceExt};
5555
use slice::CloneSliceExt;
5656
use str::{Str, StrExt};
5757
use string::{String, ToString};
58-
use sync::atomic::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
58+
use sync::atomic::{AtomicInt, ATOMIC_INT_INIT, SeqCst};
5959
use vec::Vec;
6060

6161
#[cfg(unix)] use c_str::ToCStr;
@@ -596,7 +596,7 @@ pub fn last_os_error() -> String {
596596
error_string(errno() as uint)
597597
}
598598

599-
static EXIT_STATUS: AtomicInt = INIT_ATOMIC_INT;
599+
static EXIT_STATUS: AtomicInt = ATOMIC_INT_INIT;
600600

601601
/// Sets the process exit code
602602
///

src/libstd/rand/os.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ mod imp {
8484
#[cfg(all(target_os = "linux",
8585
any(target_arch = "x86_64", target_arch = "x86", target_arch = "arm")))]
8686
fn is_getrandom_available() -> bool {
87-
use sync::atomic::{AtomicBool, INIT_ATOMIC_BOOL, Relaxed};
87+
use sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Relaxed};
8888

89-
static GETRANDOM_CHECKED: AtomicBool = INIT_ATOMIC_BOOL;
90-
static GETRANDOM_AVAILABLE: AtomicBool = INIT_ATOMIC_BOOL;
89+
static GETRANDOM_CHECKED: AtomicBool = ATOMIC_BOOL_INIT;
90+
static GETRANDOM_AVAILABLE: AtomicBool = ATOMIC_BOOL_INIT;
9191

9292
if !GETRANDOM_CHECKED.load(Relaxed) {
9393
let mut buf: [u8; 0] = [];

src/libstd/rt/backtrace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub use sys::backtrace::write;
2222
// For now logging is turned off by default, and this function checks to see
2323
// whether the magical environment variable is present to see if it's turned on.
2424
pub fn log_enabled() -> bool {
25-
static ENABLED: atomic::AtomicInt = atomic::INIT_ATOMIC_INT;
25+
static ENABLED: atomic::AtomicInt = atomic::ATOMIC_INT_INIT;
2626
match ENABLED.load(atomic::SeqCst) {
2727
1 => return false,
2828
2 => return true,

src/libstd/rt/exclusive.rs

-119
This file was deleted.

0 commit comments

Comments
 (0)