summary refs log tree commit diff
path: root/src/libstd/sync
AgeCommit message (Collapse)AuthorLines
2018-04-28stabilize `#[must_use]` for functions and must-use operatorsZack M. Davis-0/+2
This is in the matter of RFC 1940 and tracking issue #43302.
2018-04-12Import the `alloc` crate as `alloc_crate` in stdSimon Sapin-4/+3
… to make the name `alloc` available.
2018-02-25Rollup merge of #47970 - vlovich:condvar_wait_until, r=dtolnaykennytm-2/+214
Add Condvar APIs not susceptible to spurious wake Provide wait_until and wait_timeout_until helper wrappers that aren't susceptible to spurious wake. Additionally wait_timeout_until makes it possible to more easily write code that waits for a fixed amount of time in face of spurious wakes since otherwise each user would have to do math on adjusting the duration. Implements #47960.
2018-02-20Fix doc compile errorVitali Lovich-1/+1
2018-02-18Rollup merge of #48275 - matthiaskrgr:codespell, r=kennytm,varkorGuillaume Gomez-2/+2
fix more typos found by codespell.
2018-02-17Fix tidy violationVitali Lovich-3/+5
2018-02-17fix more typos found by codespell.Matthias Krüger-2/+2
2018-02-16Fix unit test compilationVitali Lovich-11/+17
Also fix some code snippets in documentation.
2018-02-15Fix condvar exampleGuillaume Gomez-2/+4
2018-02-13Misc fixesVitali Lovich-4/+4
Switch feature guards to unstable Add missing semicolon Remove mut that's no longer necessary
2018-02-12Fix wait_timeout valueVitali Lovich-1/+1
2018-02-05Simplify wait_timeout_until & fix condition typoVitali Lovich-8/+7
2018-02-02Review responseVitali Lovich-8/+10
Make condition closure accept mut T&. Clarify spurious wakeup documentation. Cleanup doc example code.
2018-02-02Fix typoVitali Lovich-1/+1
2018-02-02Add Condvar APIs not susceptible to spurious wakeVitali Lovich-2/+205
Provide wait_until and wait_timeout_until helper wrappers that aren't susceptible to spurious wake.
2018-01-10fix typo rwlock.rsBulat Musin-1/+1
Hi. Fixed typo: contained -> content
2017-12-27Correct a few stability attributesOliver Middleton-2/+2
2017-11-29Rollup merge of #46323 - ia0:fix_mpsc_error_conv, r=kennytmkennytm-3/+3
Fix since for mpsc_error_conversions This is a followup of #45506.
2017-11-29Rollup merge of #46287 - SimonSapin:stable-constness, r=aturonkennytm-1/+0
Stabilize const-calling existing const-fns in std Fixes #46038
2017-11-29Rollup merge of #45969 - ia0:mpsc_recv_deadline, r=alexcrichtonkennytm-2/+63
Add std::sync::mpsc::Receiver::recv_deadline() Essentially renames recv_max_until to recv_deadline (mostly copying recv_timeout documentation). This function is useful to avoid the often unnecessary call to Instant::now in recv_timeout (e.g. when the user already has a deadline). A concrete example would be something along those lines: ```rust use std::sync::mpsc::Receiver; use std::time::{Duration, Instant}; /// Reads a batch of elements /// /// Returns as soon as `max_size` elements have been received or `timeout` expires. fn recv_batch_timeout<T>(receiver: &Receiver<T>, timeout: Duration, max_size: usize) -> Vec<T> { recv_batch_deadline(receiver, Instant::now() + timeout, max_size) } /// Reads a batch of elements /// /// Returns as soon as `max_size` elements have been received or `deadline` is reached. fn recv_batch_deadline<T>(receiver: &Receiver<T>, deadline: Instant, max_size: usize) -> Vec<T> { let mut result = Vec::new(); while let Ok(x) = receiver.recv_deadline(deadline) { result.push(x); if result.len() == max_size { break; } } result } ```
2017-11-28Fix doc test of previous commitJulien Cretin-0/+2
2017-11-28Fix since for mpsc_error_conversionsJulien Cretin-3/+3
2017-11-27Use an unstable feature linked to #46316Julien Cretin-1/+1
2017-11-28Rollup merge of #45506 - ia0:mpsc_recv_error_from, r=alexcrichtonkennytm-0/+27
Implement From<RecvError> for TryRecvError and RecvTimeoutError According to the documentation, it looks to me that `TryRecvError` and `RecvTimeoutError` are strict extensions of `RecvError`. As such, it makes sense to allow conversion from the latter type to the two former types without constraining future developments. This permits to write `input.recv()?` and `input.recv_timeout(timeout)?` in the same function for example.
2017-11-26Stabilize const-calling existing const-fns in stdSimon Sapin-1/+0
Fixes #46038
2017-11-18impl From<T> for RwLock<T>Eduardo Pinho-0/+11
2017-11-18impl From<T> for Mutex<T>Eduardo Pinho-0/+11
2017-11-13Add std::sync::mpsc::Receiver::recv_deadline()Julien Cretin-2/+61
Essentially renames recv_max_until to recv_deadline (mostly copying recv_timeout documentation). This function is useful to avoid the often unnecessary call to Instant::now in recv_timeout (e.g. when the user already has a deadline). A concrete example would be something along those lines: ```rust use std::sync::mpsc::Receiver; use std::time::{Duration, Instant}; /// Reads a batch of elements /// /// Returns as soon as `max_size` elements have been received or `timeout` expires. fn recv_batch_timeout<T>(receiver: &Receiver<T>, timeout: Duration, max_size: usize) -> Vec<T> { recv_batch_deadline(receiver, Instant::now() + timeout, max_size) } /// Reads a batch of elements /// /// Returns as soon as `max_size` elements have been received or `deadline` is reached. fn recv_batch_deadline<T>(receiver: &Receiver<T>, deadline: Instant, max_size: usize) -> Vec<T> { let mut result = Vec::new(); while let Ok(x) = receiver.recv_deadline(deadline) { result.push(x); if result.len() == max_size { break; } } result } ```
2017-11-08std: Remove `rand` crate and moduleAlex Crichton-3/+1
This commit removes the `rand` crate from the standard library facade as well as the `__rand` module in the standard library. Neither of these were used in any meaningful way in the standard library itself. The only need for randomness in libstd is to initialize the thread-local keys of a `HashMap`, and that unconditionally used `OsRng` defined in the standard library anyway. The cruft of the `rand` crate and the extra `rand` support in the standard library makes libstd slightly more difficult to port to new platforms, namely WebAssembly which doesn't have any randomness at all (without interfacing with JS). The purpose of this commit is to clarify and streamline randomness in libstd, focusing on how it's only required in one location, hashmap seeds. Note that the `rand` crate out of tree has almost always been a drop-in replacement for the `rand` crate in-tree, so any usage (accidental or purposeful) of the crate in-tree should switch to the `rand` crate on crates.io. This then also has the further benefit of avoiding duplication (mostly) between the two crates!
2017-11-01RwLock guards are Sync if T isRalf Jung-3/+8
Currently, the compiler requires `T` to also be `Send`. There is no reason for that. `&Rw{Read,Write}LockGuard` only provides a shared referenced to `T`, sending that across threads is safe if `T` is `Sync`.
2017-11-01Auto merge of #45267 - oconnor663:rwlock_send, r=alexcrichtonbors-1/+1
remove the `T: Sync` requirement for `RwLock<T>: Send` That requirement makes sense for containers like `Arc` that don't uniquely own their contents, but `RwLock` is not one of those. This restriction was added in https://github.com/rust-lang/rust/commit/380d23b5d4b9fb8f5f0ebf178590f61528b2483e, but it's not clear why. @hniksic and I [were discussing this on reddit](https://www.reddit.com/r/rust/comments/763o7r/blog_posts_introducing_lockfree_rust_comparing/dobcvbm/). I might be totally wrong about this change being sound, but I'm super curious to find out :)
2017-10-31Implement From<SendError<T>> for TrySendError<T>Julien Cretin-2/+11
2017-10-26Bump to 1.23 and update bootstrapAlex Crichton-1/+1
This commit updates the bootstrap compiler, bumps the version to 1.23, updates Cargo, updates books, and updates crates.io dependencies
2017-10-25Implement From<RecvError> for TryRecvError and RecvTimeoutErrorJulien Cretin-0/+18
2017-10-22Improve docs around `Once::call_once_force` and `OnceState`.Corey Farwell-13/+81
2017-10-13remove the `T: Sync` requirement for `RwLock<T>: Send`Jack O'Connor-1/+1
That requirement makes sense for containers like `Arc` that don't uniquely own their contents, but `RwLock` is not one of those. This restriction was added in https://github.com/rust-lang/rust/commit/380d23b5d4b9fb8f5f0ebf178590f61528b2483e, but it's not clear why.
2017-10-11Auto merge of #44963 - JLockerman:fix_spsc, r=alexcrichtonbors-107/+190
Improve performance of spsc_queue and stream. This PR makes two main changes: 1. It switches the `spsc_queue` node caching strategy from keeping a shared counter of the number of nodes in the cache to keeping a consumer only counter of the number of node eligible to be cached. 2. It separates the consumer and producers fields of `spsc_queue` and `stream` into a producer cache line and consumer cache line. Overall, it speeds up `mpsc` in `spsc` mode by 2-10x. Variance is higher than I'd like (that 2-10x speedup is on one benchmark), I believe this is due to the drop check in `send` (`fn stream::Queue::send:107`). I think this check can be combined with the sleep detection code into a version which only uses 1 shared variable, and only one atomic access per `send`, but I haven't looked through the select implementation enough to be sure. The code currently assumes a cache line size of 64 bytes. I added a CacheAligned newtype in `mpsc` which I expect to reuse for `shared`. It doesn't really belong there, it would probably be best put in `core::sync::atomic`, but putting it in `core` would involve making it public, which I thought would require an RFC. Benchmark runner is [here](https://github.com/JLockerman/queues/tree/3eca46279c53eb75833c5ecd416de2ac220bd022/shootout), benchmarks [here](https://github.com/JLockerman/queues/blob/3eca46279c53eb75833c5ecd416de2ac220bd022/queue_bench/src/lib.rs#L170-L293). Fixes #44512.
2017-10-10Rollup merge of #44775 - MaloJaffre:debug-struct, r=sfacklerkennytm-43/+25
Refactor to use `debug_struct` in several Debug impls Also use `pad` and derive `Debug` for `Edge`. Fixes #44771.
2017-10-09Refactor to use `debug_struct` in several Debug implsMalo Jaffré-43/+25
Fixes #44771.
2017-10-08Remove Queue::new.Joshua Lockerman-29/+5
2017-10-08cfg out Queue::new for emscriptenJLockerman-1/+1
Queue::new is only used is tests atm, which causes warnings on emscripten which does not run queue tests.
2017-10-04Add missing urls for MutexGuillaume Gomez-7/+17
2017-10-01Improve performance of spsc_queue and stream.Joshua Lockerman-99/+206
This commit makes two main changes. 1. It switches the spsc_queue node caching strategy from keeping a shared counter of the number of nodes in the cache to keeping a consumer only counter of the number of node eligible to be cached. 2. It separate the consumer and producers fields of spsc_queue and stream into a producer cache line and consumer cache line.
2017-09-22std::sync::RwLock docs improvementLucas Morales-13/+120
2017-09-16change #![feature(const_fn)] to specific gatesAlex Burka-0/+1
2017-08-17Rollup merge of #43891 - Fourchaux:master, r=steveklabnikCorey Farwell-1/+1
Fix typos & us spellings Fixing some typos and non en-US spellings. (Update of PR https://github.com/rust-lang/rust/pull/42812 )
2017-08-15use field init shorthand EVERYWHEREZack M. Davis-4/+4
Like #43008 (f668999), but _much more aggressive_.
2017-08-15Fix typos & us spellingsFourchaux-1/+1
2017-08-10Auto merge of #43582 - ivanbakel:unused_mut_ref, r=arielb1bors-1/+1
Fixed mutable vars being marked used when they weren't #### NB : bootstrapping is slow on my machine, even with `keep-stage` - fixes for occurances in the current codebase are <s>in the pipeline</s> done. This PR is being put up for review of the fix of the issue. Fixes #43526, Fixes #30280, Fixes #25049 ### Issue Whenever the compiler detected a mutable deref being used mutably, it marked an associated value as being used mutably as well. In the case of derefencing local variables which were mutable references, this incorrectly marked the reference itself being used mutably, instead of its contents - with the consequence of making the following code emit no warnings ``` fn do_thing<T>(mut arg : &mut T) { ... // don't touch arg - just deref it to access the T } ``` ### Fix Make dereferences not be counted as a mutable use, but only when they're on borrows on local variables. #### Why not on things other than local variables? * Whenever you capture a variable in a closure, it gets turned into a hidden reference - when you use it in the closure, it gets dereferenced. If the closure uses the variable mutably, that is actually a mutable use of the thing being dereffed to, so it has to be counted. * If you deref a mutable `Box` to access the contents mutably, you are using the `Box` mutably - so it has to be counted.
2017-08-08Use explicit wrapping_add to prevent potential unexpected behavior on debug ↵Stefan Schindler-1/+1
builds