about summary refs log tree commit diff
path: root/src/liballoc/arc.rs
AgeCommit message (Collapse)AuthorLines
2015-07-03Fix 'Relaaxed' typo in code commentCorey Farwell-1/+1
2015-07-03Auto merge of #26610 - aturon:fix_make_unique, r=alexcrichtonbors-79/+177
This commit resolves the race condition in the `get_mut` and `make_unique` functions, which arose through interaction with weak pointers. The basic strategy is to "lock" the weak pointer count when trying to establish uniqueness, by reusing the field as a simple spinlock. The overhead for normal use of `Arc` is expected to be minimal -- it will be *none* when only strong pointers are used, and only requires a move from atomic increment to CAS for usage of weak pointers. The commit also removes the `unsafe` and deprecated status of these functions. Closes #24880 r? @alexcrichton cc @metajack @SimonSapin @Ms2ger
2015-07-02Fix race condition in Arc's get_mut and make_unqiueAaron Turon-79/+177
This commit resolves the race condition in the `get_mut` and `make_unique` functions, which arose through interaction with weak pointers. The basic strategy is to "lock" the weak pointer count when trying to establish uniqueness, by reusing the field as a simple spinlock. The overhead for normal use of `Arc` is expected to be minimal -- it will be *none* when only strong pointers are used, and only requires a move from atomic increment to CAS for usage of weak pointers. The commit also removes the `unsafe` and deprecated status of these functions. Along the way, the commit also improves several memory orderings, and adds commentary about why various orderings suffice.
2015-07-01Implement CoerceUnsized for arc::WeakRemi Rampin-0/+2
2015-06-24Make `align_of` behave like `min_align_of`.Huon Wilson-3/+3
This removes a footgun, since it is a reasonable assumption to make that pointers to `T` will be aligned to `align_of::<T>()`. This also matches the behaviour of C/C++. `min_align_of` is now deprecated. Closes #21611.
2015-06-17More test fixes and fallout of stability changesAlex Crichton-1/+1
2015-06-17std: Move free-functions to associated functionsAlex Crichton-4/+22
This commit moves the free functions in the `rc`, `arc`, and `boxed` modules to associated functions on their respective types, following the recent trend towards this pattern. The previous free functions are all left in-place with `#[deprecated]` pointers towards the new locations. This commit also deprecates `arc::get_mut` and `Arc::make_unique` with no replacement as they are racy in the face of weak pointers.
2015-06-17Fallout in tests and docs from feature renamingsAlex Crichton-10/+10
2015-06-17alloc: Split apart the global `alloc` featureAlex Crichton-8/+8
2015-06-09Revert "Added AsRef implementations for Arc and Rc"Alex Crichton-9/+0
This reverts commit 7f3ae0aa26d24100379ae0f3eef29916a32f4e79.
2015-06-06Remove many unneeded feature annotations in the docsSteve Klabnik-3/+0
When things get stabilized, they don't always have their docs updated to remove the gate.
2015-06-04Added AsRef implementations for Arc and RcMarkus Westerlind-0/+9
2015-05-30Mark Arc function get_mut and method make_unique unsafeUlrik Sverdrup-35/+56
This is a temporary mitigation for issue #24880 which points out that these functions are racy in a particular situation where weak pointers exist. To mitigate this, mark the functions unsafe until this can be fixed or another decision is made. This is a breaking change to unstable API, because the new version requires an `unsafe` block. Review carefully if weak pointers may race for any uses of this API and consider abandoning it. [breaking-change]
2015-05-19Fix rebase conflictsAriel Ben-Yehuda-2/+6
2015-05-17Make `Arc` support DSTsP1start-36/+50
2015-05-09Squeeze the last bits of `task`s in documentation in favor of `thread`Barosl Lee-4/+4
An automated script was run against the `.rs` and `.md` files, subsituting every occurrence of `task` with `thread`. In the `.rs` files, only the texts in the comment blocks were affected.
2015-04-28Register new snapshotsTamir Duberstein-2/+0
2015-04-22Relax bounds on Default implementation for Arc.Ulrik Sverdrup-1/+1
Send + Sync are overly restrictive, follow other traits for Arc.
2015-04-21rollup merge of #24541: alexcrichton/issue-24538Alex Crichton-1/+0
This is an implementation of [RFC 1030][rfc] which adds these traits to the prelude and additionally removes all inherent `into_iter` methods on collections in favor of the trait implementation (which is now accessible by default). [rfc]: https://github.com/rust-lang/rfcs/pull/1030 This is technically a breaking change due to the prelude additions and removal of inherent methods, but it is expected that essentially no code breaks in practice. [breaking-change] Closes #24538
2015-04-20Simplify alloc::arc::Arc example in doc-commentCorey Farwell-1/+1
As far as I can tell, this conversion to integer to floating point does not need to happen and is beside the point
2015-04-17std: Add Default/IntoIterator/ToOwned to the preludeAlex Crichton-1/+0
This is an implementation of [RFC 1030][rfc] which adds these traits to the prelude and additionally removes all inherent `into_iter` methods on collections in favor of the trait implementation (which is now accessible by default). [rfc]: https://github.com/rust-lang/rfcs/pull/1030 This is technically a breaking change due to the prelude additions and removal of inherent methods, but it is expected that essentially no code breaks in practice. [breaking-change] Closes #24538
2015-04-15Fix some typos.Ms2ger-1/+1
2015-04-07alloc: impl fmt::Pointer for Rc, Arc and BoxRicho Healey-0/+7
Closes #24091
2015-04-04Removed explicit lifetimes for `get_mut`. Fixed the doc test.Dzmitry Malyshau-1/+3
2015-04-04Renamed Arc::try_unique to get_mutDzmitry Malyshau-23/+21
2015-04-04Rollup merge of #23997 - richo:typos, r=huonwManish Goregaokar-1/+1
Kinda hoped I'd spot something else for this PR, but then didn't.
2015-04-02liballoc: fix typoRicho Healey-1/+1
2015-04-01rollup merge of #23176: huonw/rm-boundsAlex Crichton-2/+2
2015-04-01Test fixes and rebase conflicts, round 1Alex Crichton-1/+4
2015-04-02Rollup merge of #23844 - kvark:try_unique, r=alexcrichtonManish Goregaokar-6/+50
While trying to implement parallel ECS processing, I stumbled upon the need to mutate `Arc` contents. The only existed method that allowed that was `make_unique`, but it has issues: - it may clone the data as if nothing happened, where the program may just need to crash - it forces `Clone` bound, which I don't have The new `try_unique` allows accessing the contents mutably without `Clone` bound and error out if the pointer is not unique.
2015-03-31Added Arc::try_uniqueDzmitry Malyshau-6/+50
2015-03-31replace deprecated as_slice()Emeliov Dmitrii-1/+1
2015-03-28Rollup merge of #23803 - richo:unused-braces, r=ManishearthManish Goregaokar-1/+1
Pretty much what it says on the tin.
2015-03-28cleanup: Remove unused braces in use statementsRicho Healey-1/+1
2015-03-27rollup merge of #23775: alexcrichton/fix-flaky-testAlex Crichton-2/+2
Windows gets quite unhappy when a thread fails while the main thread is exiting, frequently leading to process deadlock. This has been causing quite a few deadlocks on the windows bots recently. The child threads are presumably failing because the `println!` is failing due to the main thread being shut down.
2015-03-27rollup merge of #23743: Adenilson/addInfoArcClone01Alex Crichton-0/+3
Adding more information about the behavior of Arc/Rc when you perform a clone() call.
2015-03-27alloc: Don't run some Arc doc testsAlex Crichton-2/+2
Windows gets quite unhappy when a thread fails while the main thread is exiting, frequently leading to process deadlock. This has been causing quite a few deadlocks on the windows bots recently. The child threads are presumably failing because the `println!` is failing due to the main thread being shut down.
2015-03-26Adding more information about the behavior of Arc/RcAdenilson Cavalcanti-0/+3
when you perform a clone() call.
2015-03-26Switch drop-flag to `u8` to allow special tags to instrument state.Felix S. Klock II-2/+3
Refactored code so that the drop-flag values for initialized (`DTOR_NEEDED`) versus dropped (`DTOR_DONE`) are given explicit names. Add `mem::dropped()` (which with `DTOR_DONE == 0` is semantically the same as `mem::zeroed`, but the point is that it abstracts away from the particular choice of value for `DTOR_DONE`). Filling-drop needs to use something other than `ptr::read_and_zero`, so I added such a function: `ptr::read_and_drop`. But, libraries should not use it if they can otherwise avoid it. Fixes to tests to accommodate filling-drop.
2015-03-24Remove unnecessary bounds from Drop impl for `Arc` and `arc::Weak` andFelix S. Klock II-3/+3
one of the helper method impls.
2015-03-23Test fixes and rebase conflicts, round 2Alex Crichton-34/+42
2015-03-23Add #![feature] attributes to doctestsBrian Anderson-0/+8
2015-03-18liballoc: Partially inline the refcount manipulation in the ArcPatrick Walton-8/+18
destructor.
2015-03-13Remove explicit syntax highlight from docs.Joseph Crail-1/+1
2015-03-11Example -> ExamplesSteve Klabnik-1/+1
This brings comments in line with https://github.com/rust-lang/rfcs/blob/master/text/0505-api-comment-conventions.md#using-markdown
2015-03-08Remove unneeded `T: Send + Sync` bounds from `Arc`.Huon Wilson-5/+5
The requirement `T: Send + Sync` only matters if the `Arc` crosses thread boundaries, and that is adequately controlled by the impls of `Send`/`Sync` for `Arc` itself. If `T` doesn't satisfy the bounds, then the `Arc` cannot cross thread boundaries and so everything is still safe (`Arc` just acts like an expensive `Rc`).
2015-03-03Add `: Box<_>` or `::Box<_>` type annotations to various places.Felix S. Klock II-1/+3
This is the kind of change that one is expected to need to make to accommodate overloaded-`box`. ---- Note that this is not *all* of the changes necessary to accommodate Issue 22181. It is merely the subset of those cases where there was already a let-binding in place that made it easy to add the necesasry type ascription. (For unnamed intermediate `Box` values, one must go down a different route; `Box::new` is the option that maximizes portability, but has potential inefficiency depending on whether the call is inlined.) ---- There is one place worth note, `run-pass/coerce-match.rs`, where I used an ugly form of `Box<_>` type ascription where I would have preferred to use `Box::new` to accommodate overloaded-`box`. I deliberately did not use `Box::new` here, because that is already done in coerce-match-calls.rs. ---- Precursor for overloaded-`box` and placement-`in`; see Issue 22181.
2015-02-28std: Implement stdio for `std::io`Alex Crichton-10/+13
This is an implementation of RFC 899 and adds stdio functionality to the new `std::io` module. Details of the API can be found on the RFC, but from a high level: * `io::{stdin, stdout, stderr}` constructors are now available. There are also `*_raw` variants for unbuffered and unlocked access. * All handles are globally shared (excluding raw variants). * The stderr handle is no longer buffered. * All handles can be explicitly locked (excluding the raw variants). The `print!` and `println!` machinery has not yet been hooked up to these streams just yet. The `std::fmt::output` module has also not yet been implemented as part of this commit.
2015-02-27Auto merge of #22573 - nwin:impl-debug-rwlock-weak, r=Manishearthbors-0/+7
Implements `Debug` for `RwLock` and `arc::Weak` in the same way it is implemented for `rc::Weak` (basically copy & paste). The lack of this implementation prevents the automatic implementation of `Debug` for structs containing members of these types.
2015-02-26Implement `Debug` for `RwLock`, `arc::Weak` and `Mutex`nwin-0/+7