about summary refs log tree commit diff
path: root/src/libstd/sync/mpsc
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-3/+2
… to make the name `alloc` available.
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 #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-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-10-31Implement From<SendError<T>> for TrySendError<T>Julien Cretin-2/+11
2017-10-25Implement From<RecvError> for TryRecvError and RecvTimeoutErrorJulien Cretin-0/+18
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-09Refactor to use `debug_struct` in several Debug implsMalo Jaffré-37/+5
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-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-08-15use field init shorthand EVERYWHEREZack M. Davis-4/+4
Like #43008 (f668999), but _much more aggressive_.
2017-06-21Rollup merge of #42397 - sfackler:syncsender-sync, r=alexcrichtonCorey Farwell-5/+0
Implement Sync for SyncSender r? @alexcrichton
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-5/+5
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-5/+5
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-26Adding links and examples for various mspc pages #29377projektir-29/+254
2017-04-22Fix invalid linkageGuillaume Gomez-1/+1
2017-04-08Adding links around Sender/SyncSender/Receiver errors; Adding more ↵projektir-50/+84
documentation to channel() and sync_channel(); adding more links #29377
2017-04-03Fix styling issuesBryan Tan-6/+17
2017-03-31Fix warnings in examplesBryan Tan-9/+9
2017-03-31Fix broken links to std::iter::Iterator::nextBryan Tan-2/+2
2017-03-31Add links and examples to std::sync::mpsc docs (#29377)Bryan Tan-31/+136
This change adds links to to `Receiver`, `Iter`, `TryIter`, `IntoIter`, `Sender`, `SyncSender`, `SendError`, `RecvError`, `TryRecvError`, `RecvTimeoutError`, `TrySendError`, `Sender::send`, `SyncSender::send`, `SyncSender::try_send`, `Receiver::recv`, `Receiver::recv_timeout`, `Receiver::iter`, and `Receiver::try_iter`. Examples added to `Receiver`, `Sender`, `Receiver::iter`.
2017-03-30Add links to std::sync::mpsc docs #29377Bryan Tan-15/+25
2017-03-13Remove function invokation parens from documentation links.Corey Farwell-6/+6
This was never established as a convention we should follow in the 'More API Documentation Conventions' RFC: https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md
2016-12-20Rollup merge of #38006 - frewsxcv:libstd-debug, r=alexcrichtonAlex Crichton-0/+3
Implement `fmt::Debug` for all structures in libstd. Part of https://github.com/rust-lang/rust/issues/31869. Also turn on the `missing_debug_implementations` lint at the crate level.
2016-12-19Rollup merge of #38421 - apasel422:issue-36934, r=alexcrichtonSeo Sanghyeon-328/+328
Replace invalid use of `&mut` with `UnsafeCell` in `std::sync::mpsc` Closes #36934 r? @alexcrichton
2016-12-18Implement `fmt::Debug` for all structures in libstd.Corey Farwell-0/+3
Part of https://github.com/rust-lang/rust/issues/31869. Also turn on the `missing_debug_implementations` lint at the crate level.
2016-12-16Replace invalid use of `&mut` with `UnsafeCell` in `std::sync::mpsc`Andrew Paseltiner-328/+328
Closes #36934
2016-12-15Stabilize std::sync::mpsc::Receiver::try_iterAaron Turon-3/+3
2016-12-07Improve and fix mpsc documentationCobrand-9/+20
Closes #37915 This commit enhances documentation with several links and fixes an error in the `sync_channel` documentation as well: `send` doesn't panic when the senders are all disconnected
2016-11-24Define `bound` argument in std::sync::mpsc::sync_channelfkjogu-5/+5
The `bound` argument in `std::sync::mpsc::sync:channel(bound: usize)` was not defined in the documentation.
2016-11-02Add Error implementation for std::sync::mpsc::RecvTimeoutError.Mark-Simulacrum-0/+32
2016-10-12Deprecate `Reflect`Nick Cameron-3/+2
[tracking issue](https://github.com/rust-lang/rust/issues/27749)
2016-10-05Auto merge of #36893 - apasel422:issue-32114, r=alexcrichtonbors-0/+9
Restore `DISCONNECTED` state in `oneshot::Packet::send` Closes #32114 I'm not sure if this is the best approach, but the current action of swapping `DISCONNECTED` with `DATA` seems wrong. Additionally, it is strange that the `send` method (and others in the `oneshot` module) takes `&mut self` despite performing atomic operations, as this requires extra discipline to avoid data races and lets us use methods like `AtomicUsize::get_mut` instead of methods that require a memory ordering.
2016-10-05Restore `DISCONNECTED` state in `oneshot::Packet::send`Andrew Paseltiner-0/+9
Closes #32114
2016-10-04Rollup merge of #36902 - ollie27:stab_impls, r=alexcrichtonManish Goregaokar-2/+0
std: Correct stability attributes for some implementations These are displayed by rustdoc so should be correct.
2016-10-02Add a platform-abstraction tidy scriptBrian Anderson-1/+1
This is intended to maintain existing standards of code organization in hopes that the standard library will continue to be refactored to isolate platform-specific bits, making porting easier; where "standard library" roughly means "all the dependencies of the std and test crates". This generally means placing restrictions on where `cfg(unix)`, `cfg(windows)`, `cfg(target_os)` and `cfg(target_env)` may appear, the basic objective being to isolate platform-specific code to the platform-specific `std::sys` modules, and to the allocation, unwinding, and libc crates. Following are the basic rules, though there are currently exceptions: - core may not have platform-specific code - liballoc_system may have platform-specific code - liballoc_jemalloc may have platform-specific code - libpanic_abort may have platform-specific code - libpanic_unwind may have platform-specific code - other crates in the std facade may not - std may have platform-specific code in the following places - sys/unix/ - sys/windows/ - os/ There are plenty of exceptions today though, noted in the whitelist.
2016-10-01std: Correct stability attributes for some implementationsOliver Middleton-2/+0
These are displayed by rustdoc so should be correct.