about summary refs log tree commit diff
path: root/src/libstd/comm
AgeCommit message (Collapse)AuthorLines
2014-03-28syntax: Accept meta matchers in macrosAlex Crichton-3/+3
This removes the `attr` matcher and adds a `meta` matcher. The previous `attr` matcher is now ambiguous because it doesn't disambiguate whether it means inner attribute or outer attribute. The new behavior can still be achieved by taking an argument of the form `#[$foo:meta]` (the brackets are part of the macro pattern). Closes #13067
2014-03-24comm: Implement synchronous channelsAlex Crichton-2/+1217
This commit contains an implementation of synchronous, bounded channels for Rust. This is an implementation of the proposal made last January [1]. These channels are built on mutexes, and currently focus on a working implementation rather than speed. Receivers for sync channels have select() implemented for them, but there is currently no implementation of select() for sync senders. Rust will continue to provide both synchronous and asynchronous channels as part of the standard distribution, there is no intent to remove asynchronous channels. This flavor of channels is meant to provide an alternative to asynchronous channels because like green tasks, asynchronous channels are not appropriate for all situations. [1] - https://mail.mozilla.org/pipermail/rust-dev/2014-January/007924.html
2014-03-23std: Move NativeMutex from &mut self to &selfAlex Crichton-1/+1
The proper usage of shared types is now sharing through `&self` rather than `&mut self` because the mutable version will provide stronger guarantees (no aliasing on *any* thread).
2014-03-22std::comm: Remove Freeze / NoFreezeFlavio Percoco-6/+4
2014-03-20rename std::vec -> std::sliceDaniel Micay-2/+2
Closes #12702
2014-03-13std: Rename Chan/Port types and constructorAlex Crichton-534/+535
* Chan<T> => Sender<T> * Port<T> => Receiver<T> * Chan::new() => channel() * constructor returns (Sender, Receiver) instead of (Receiver, Sender) * local variables named `port` renamed to `rx` * local variables named `chan` renamed to `tx` Closes #11765
2014-03-12std: Relax an assertion in oneshot selectionAlex Crichton-7/+64
The assertion was erroneously ensuring that there was no data on the port when the port had selection aborted on it. This assertion was written in error because it's possible for data to be waiting on a port, even after it was disconnected. When aborting selection, if we see that there's data on the port, then we return true that data is available on the port. Closes #12802
2014-03-06fix typos with with repeated words, just like this sentence.Kang Seonghoon-1/+1
2014-02-28std: Change assert_eq!() to use {} instead of {:?}Alex Crichton-1/+1
Formatting via reflection has been a little questionable for some time now, and it's a little unfortunate that one of the standard macros will silently use reflection when you weren't expecting it. This adds small bits of code bloat to libraries, as well as not always being necessary. In light of this information, this commit switches assert_eq!() to using {} in the error message instead of {:?}. In updating existing code, there were a few error cases that I encountered: * It's impossible to define Show for [T, ..N]. I think DST will alleviate this because we can define Show for [T]. * A few types here and there just needed a #[deriving(Show)] * Type parameters needed a Show bound, I often moved this to `assert!(a == b)` * `Path` doesn't implement `Show`, so assert_eq!() cannot be used on two paths. I don't think this is much of a regression though because {:?} on paths looks awful (it's a byte array). Concretely speaking, this shaved 10K off a 656K binary. Not a lot, but sometime significant for smaller binaries.
2014-02-27std: Export the select! macroAlex Crichton-16/+0
Mark it as #[experimental] for now. In theory this attribute will be read in the future. I believe that the implementation is solid enough for general use, although I would not be surprised if there were bugs in it still. I think that it's at the point now where public usage of it will start to uncover hopefully the last few remaining bugs. Closes #12044
2014-02-21auto merge of #12419 : huonw/rust/compiler-unsafe, r=alexcrichtonbors-17/+13
Previously an `unsafe` block created by the compiler (like those in the formatting macros) would be "ignored" if surrounded by `unsafe`, that is, the internal unsafety would be being legitimised by the external block: unsafe { println!("...") } =(expansion)=> unsafe { ... unsafe { ... } } And the code in the inner block would be using the outer block, making it considered used (and the inner one considered unused). This patch forces the compiler to create a new unsafe context for compiler generated blocks, so that their internal unsafety doesn't escape to external blocks. Fixes #12418.
2014-02-20rustc: avoid compiler generated `unsafe` blocks leaking.Huon Wilson-17/+13
Previously an `unsafe` block created by the compiler (like those in the formatting macros) would be "ignored" if surrounded by `unsafe`, that is, the internal unsafety would be being legitimised by the external block: unsafe { println!("...") } =(expansion)=> unsafe { ... unsafe { ... } } And the code in the inner block would be using the outer block, making it considered used (and the inner one considered unused). This patch forces the compiler to create a new unsafe context for compiler generated blocks, so that their internal unsafety doesn't escape to external blocks. Fixes #12418.
2014-02-19Fix sending/try_recv on channels off the runtimeAlex Crichton-10/+49
The fairness yield mistakenly called `Local::take()` which meant that it would only work if a local task was available. In theory sending on a channel (or calling try_recv) requires no runtime because it never blocks, so there's no reason it shouldn't support such a use case. Closes #12391
2014-02-18auto merge of #12345 : huonw/rust/speeling, r=cmrbors-1/+1
2014-02-17Fix a deadlock in channels, again.Alex Crichton-4/+4
This deadlock was caused when the channel was closed at just the right time, so the extra `self.cnt.fetch_add` actually should have preserved the DISCONNECTED state of the channel. by modifying this the channel entered a state such that the port would never succeed in dropping. This also moves the increment of self.steals until after the MAX_STEALS block. The reason for this is that in 'fn recv()' the steals variable is decremented immediately after the try_recv(), which could in theory set steals to -1 if it was previously set to 0 in try_recv(). Closes #12340
2014-02-18Spellcheck library docs.Huon Wilson-1/+1
2014-02-15auto merge of #12302 : alexcrichton/rust/issue-12295, r=brsonbors-7/+28
The previous code erroneously assumed that 'steals > cnt' was always true, but that was a false assumption. The code was altered to decrement steals to a minimum of 0 instead of taking all of cnt into account. I didn't include the exact test from #12295 because it could run for quite awhile, and instead set the threshold for MAX_STEALS to much lower during testing. I found that this triggered the old bug quite frequently when running without this fix. Closes #12295
2014-02-15auto merge of #12298 : alexcrichton/rust/rustdoc-testing, r=sfacklerbors-1/+1
It's too easy to forget the `rust` tag to test something. Closes #11698
2014-02-15Correctly reset steals when hitting MAX_STEALSAlex Crichton-7/+28
The previous code erroneously assumed that 'steals > cnt' was always true, but that was a false assumption. The code was altered to decrement steals to a minimum of 0 instead of taking all of cnt into account. I didn't include the exact test from #12295 because it could run for quite awhile, and instead set the threshold for MAX_STEALS to much lower during testing. I found that this triggered the old bug quite frequently when running without this fix. Closes #12295
2014-02-16Convert some unnecessary StaticNativeMutexes to NativeMutexes.Huon Wilson-4/+3
2014-02-16std: Rename unstable::mutex::Mutex to StaticNativeMutex.Huon Wilson-3/+3
This better reflects its purpose and design.
2014-02-16std: add an RAII unlocker to Mutex.Huon Wilson-4/+3
This automatically unlocks its lock when it goes out of scope, and provides a safe(ish) method to call .wait.
2014-02-14Fix all code examplesAlex Crichton-1/+1
2014-02-13Rebase conflicts from this giant stack of patchesAlex Crichton-3/+3
List of PRs contained in this rollup: Closes #12167 r=alexcrichton Closes #12200 r=alexcrichton Closes #12206 r=pcwalton Closes #12209 r=huonw Closes #12211 r=pcwalton Closes #12217 r=brson Closes #12218 r=alexcrichton Closes #12220 r=alexcrichton Closes #12222 r=kballard Closes #12225 r=alexcrichton Closes #12227 r=kballard Closes #12237 r=alexcrichton Closes #12240 r=kballard
2014-02-13Relax an assertion in start_selection()Alex Crichton-10/+122
It asserted that the previous count was always nonnegative, but DISCONNECTED is a valid value for it to see. In order to continue to remember to store DISCONNECTED after DISCONNECTED was seen, I also added a helper method. Closes #12226
2014-02-13std::comm: replace Handle.id with a method.Huon Wilson-12/+12
The `id` shouldn't be changed by external code, and exposing it publicly allows to be accidentally changed. Also, remove the first element special case in the `select!` macro.
2014-02-11Test fixes and rebase conflictsAlex Crichton-40/+27
2014-02-11Rewrite channels yet again for upgradeabilityAlex Crichton-618/+1824
This, the Nth rewrite of channels, is not a rewrite of the core logic behind channels, but rather their API usage. In the past, we had the distinction between oneshot, stream, and shared channels, but the most recent rewrite dropped oneshots in favor of streams and shared channels. This distinction of stream vs shared has shown that it's not quite what we'd like either, and this moves the `std::comm` module in the direction of "one channel to rule them all". There now remains only one Chan and one Port. This new channel is actually a hybrid oneshot/stream/shared channel under the hood in order to optimize for the use cases in question. Additionally, this also reduces the cognitive burden of having to choose between a Chan or a SharedChan in an API. My simple benchmarks show no reduction in efficiency over the existing channels today, and a 3x improvement in the oneshot case. I sadly don't have a pre-last-rewrite compiler to test out the old old oneshots, but I would imagine that the performance is comparable, but slightly slower (due to atomic reference counting). This commit also brings the bonus bugfix to channels that the pending queue of messages are all dropped when a Port disappears rather then when both the Port and the Chan disappear.
2014-02-11Shuffle around ownership in concurrent queuesAlex Crichton-73/+71
Beforehand, using a concurrent queue always mandated that the "shared state" be stored internally to the queues in order to provide a safe interface. This isn't quite as flexible as one would want in some circumstances, so instead this commit moves the queues to not containing the shared state. The queues no longer have a "default useful safe" interface, but rather a "default safe" interface (minus the useful part). The queues have to be shared manually through an Arc or some other means. This allows them to be a little more flexible at the cost of a usability hindrance. I plan on using this new flexibility to upgrade a channel to a shared channel seamlessly.
2014-02-11Move replace and swap to std::mem. Get rid of std::utilEdward Wang-1/+0
Also move Void to std::any, move drop to std::mem and reexport in prelude.
2014-02-03std: Remove try_send_deferred plus all falloutAlex Crichton-13/+7
Now that extra::sync primitives are built on a proper mutex instead of a pthreads one, there's no longer any use for this function.
2014-02-03std: Fix tests with io_error usageAlex Crichton-1/+1
2014-01-31Introduce marker types for indicating variance and for opting outNiko Matsakis-9/+22
of builtin bounds. Fixes #10834. Fixes #11385. cc #5922.
2014-01-30Remove Times traitBrendan Zabarauskas-19/+19
`Times::times` was always a second-class loop because it did not support the `break` and `continue` operations. Its playful appeal was then lost after `do` was disabled for closures. It's time to let this one go.
2014-01-29Removing do keyword from libstd and librustcScott Lawrence-73/+73
2014-01-26Fix privacy fallout from previous changeAlex Crichton-1/+1
2014-01-25auto merge of #11808 : huonw/rust/std-visible-types, r=brsonbors-1/+2
These are either returned from public functions, and really should appear in the documentation, but don't since they're private, or are implementation details that are currently public.
2014-01-26std,extra: Make some types public and other private.Huon Wilson-1/+2
These are either returned from public functions, and really should appear in the documentation, but don't since they're private, or are implementation details that are currently public.
2014-01-25auto merge of #11790 : lfairy/rust/rename-num-consts, r=alexcrichtonbors-5/+5
The following are renamed: * `min_value` => `MIN` * `max_value` => `MAX` * `bits` => `BITS` * `bytes` => `BYTES` All tests pass, except for `run-pass/phase-syntax-link-does-resolve.rs`. I doubt that failure is related, though. Fixes #10010.
2014-01-25Uppercase numeric constantsChris Wong-5/+5
The following are renamed: * `min_value` => `MIN` * `max_value` => `MAX` * `bits` => `BITS` * `bytes` => `BYTES` Fixes #10010.
2014-01-24Fix a spuriously tripped assert in select()Alex Crichton-1/+4
The race here happened when a port had its deschedule in select() canceled, but the other chan had already been dropped. This meant that the DISCONNECTED case was hit in abort_selection, but the to_wake cell hadn't been emptied yet (this was done after aborting), causing an assert in abort_selection to trip. To fix this, the to_wake cell is just emptied before abort_selection is called (we know that we're the owner of it already).
2014-01-18Rename iterators for consistencyPalmer Cox-7/+7
Rename existing iterators to get rid of the Iterator suffix and to give them names that better describe the things being iterated over.
2014-01-16Fix test to account for new temporary lifetime rules, which cause the ↵Niko Matsakis-1/+1
channel to be dropped prematurely.
2014-01-15Allow more "error" values in try_recv()Alex Crichton-19/+94
This should allow callers to know whether the channel was empty or disconnected without having to block. Closes #11087
2014-01-07std: Fill in all missing importsAlex Crichton-1/+1
Fallout from the previous commits
2013-12-29Actually block in a windows cvarAlex Crichton-3/+0
Turns out with an argument of 0 the function always returns immediately! Closes #11003
2013-12-29auto merge of #11134 : lucab/rust/lucab/libstd-doc, r=cmrbors-1/+1
Uniform the short title of modules provided by libstd, in order to make their roles more explicit when glancing at the index.
2013-12-28Guard a maybe_yield in Chan with can_reschedAlex Crichton-1/+1
I forgot to add this back in after I removed can_resched and then realized I had to add it back.
2013-12-27std: uniform modules titles for docLuca Bruno-1/+1
This commit uniforms the short title of modules provided by libstd, in order to make their roles more explicit when glancing at the index. Signed-off-by: Luca Bruno <lucab@debian.org>
2013-12-24std: Remove must deferred sending functionsAlex Crichton-34/+5
These functions are all unnecessary now, and they only have meaning in the M:N context. Removing these functions uncovered a bug in the librustuv timer bindings, but it was fairly easy to cover (and the test is already committed). These cannot be completely removed just yet due to their usage in the WaitQueue of extra::sync, and until the mutex in libextra is rewritten it will not be possible to remove the deferred sends for channels.