about summary refs log tree commit diff
path: root/src/libstd/sync
AgeCommit message (Collapse)AuthorLines
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
2017-08-01Fixed all unnecessary muts in language coreIsaac van Bakel-1/+1
2017-07-10Correct some stability attributesOliver Middleton-3/+3
These show up in rustdoc so need to be correct.
2017-06-22Ensure Guard types impl Display & DebugChris MacNaughton-0/+21
Fixes #24372
2017-06-21Rollup merge of #42397 - sfackler:syncsender-sync, r=alexcrichtonCorey Farwell-5/+0
Implement Sync for SyncSender r? @alexcrichton
2017-06-15Fix condvar.wait(distant future) return immediately on OSXStepan Koltsov-15/+51
Fixes issue #37440: `pthread_cond_timedwait` on macOS Sierra seems to overflow `ts_sec` parameter and returns immediately. To work around this problem patch rounds timeout down to approximately 1000 years. Patch also fixes overflow when converting `u64` to `time_t`.
2017-06-02Implement Sync for SyncSenderSteven Fackler-5/+0
2017-06-02Rewrite `Receiver::try_iter` doc example to show resulting values.Corey Farwell-8/+13
2017-06-02Rewrite `Receiver::iter` doc example to show resulting values.Corey Farwell-6/+8
2017-06-01Auto merge of #42281 - eddyb:well-adjusted, r=nikomatsakisbors-10/+10
Decompose Adjustment into smaller steps and remove the method map. The method map held method callee information for: * actual method calls (`x.f(...)`) * overloaded unary, binary, indexing and call operators * *every overloaded deref adjustment* (many can exist for each expression) That last one was a historical ~~accident~~ hack, and part of the motivation for this PR, along with: * a desire to compose adjustments more freely * containing the autoderef logic better to avoid mutation within an inference snapshot * not creating `TyFnDef` types which are incompatible with the original one * i.e. we used to take a`TyFnDef`'s `for<'a> &'a T -> &'a U` signature and instantiate `'a` using a region inference variable, *then* package the resulting `&'b T -> &'b U` signature in another `TyFnDef`, while keeping *the same* `DefId` and `Substs` * to fix #3548 by explicitly writing autorefs for the RHS of comparison operators Individual commits tell their own story, of "atomic" changes avoiding breaking semantics. Future work based on this PR could include: * removing the signature from `TyFnDef`, now that it's always "canonical" * some questions of variance remain, as subtyping *still* treats the signature differently * moving part of the typeck logic for methods, autoderef and coercion into `rustc::traits` * allowing LUB coercions (joining multiple expressions) to "stack up" many adjustments * transitive coercions (e.g. reify or unsize after multiple steps of autoderef) r? @nikomatsakis
2017-06-01tests: fix fallout from empowering unused_allocation in comparisons.Eduard-Mihai Burtescu-10/+10
2017-05-31Rewrite doc examples for `Receiver::recv_timeout`.Corey Farwell-4/+33
2017-05-22libstd/sync/mpsc: relicense under rust licenseDmitry Vyukov-54/+20
These files are licensed under a different license than the rest of the codebase. This causes potential issues and inconveniences. Relicense these files under the standard license. I hold original copyright on that code. Fixes #36556
2017-05-20Auto merge of #42111 - ollie27:stab, r=Mark-Simulacrumbors-9/+9
Correct some stability versions These were found by running tidy on stable versions of rust and finding features stabilised with the wrong version numbers.
2017-05-20Correct some stability versionsOliver Middleton-9/+9
These were found by running tidy on stable versions of rust and finding features stabilised with the wrong version numbers.
2017-05-18fix typo in libstd/sync/mpsc/mod.rs docsDenis Andrejew-1/+1
2017-04-29need to pick a new feature nameRalf Jung-1/+1
2017-04-29MutexGuard<T> may be Sync only if T is SyncRalf Jung-5/+3
Also remove some unnecessary unsafe impl from the tests.
2017-04-26Adding links and examples for various mspc pages #29377projektir-29/+254