about summary refs log tree commit diff
path: root/src/libsync
AgeCommit message (Collapse)AuthorLines
2014-05-14libsync: Remove all uses of `~str` from `libsync`Patrick Walton-1/+1
2014-05-14Optimize common path of Once::doitStepan Koltsov-0/+5
Optimize `Once::doit`: perform optimistic check that initializtion is already completed. `load` is much cheaper than `fetch_add` at least on x86_64. Verified with this test: ``` static mut o: one::Once = one::ONCE_INIT; unsafe { loop { let start = time::precise_time_ns(); let iters = 50000000u64; for _ in range(0, iters) { o.doit(|| { println!("once!"); }); } let end = time::precise_time_ns(); let ps_per_iter = 1000 * (end - start) / iters; println!("{} ps per iter", ps_per_iter); // confuse the optimizer o.doit(|| { println!("once!"); }); } } ``` Test executed on Mac, Intel Core i7 2GHz. Result is: * 20ns per iteration without patch * 4ns per iteration with this patch applied Once.doit could be even faster (800ps per iteration), if `doit` function was split into a pair of `doit`/`doit_slow`, and `doit` marked as `#[inline]` like this: ``` #[inline(always)] pub fn doit(&self, f: ||) { if self.cnt.load(atomics::SeqCst) < 0 { return } self.doit_slow(f); } fn doit_slow(&self, f: ||) { ... } ```
2014-05-12Add the patch number to version strings. Closes #13289Brian Anderson-1/+1
2014-05-11heap: replace `exchange_free` with `deallocate`Daniel Micay-5/+5
The `std::rt::heap` API is Rust's global allocator, so there's no need to have this as a separate API.
2014-05-11core: Remove the cast moduleAlex Crichton-16/+15
This commit revisits the `cast` module in libcore and libstd, and scrutinizes all functions inside of it. The result was to remove the `cast` module entirely, folding all functionality into the `mem` module. Specifically, this is the fate of each function in the `cast` module. * transmute - This function was moved to `mem`, but it is now marked as #[unstable]. This is due to planned changes to the `transmute` function and how it can be invoked (see the #[unstable] comment). For more information, see RFC 5 and #12898 * transmute_copy - This function was moved to `mem`, with clarification that is is not an error to invoke it with T/U that are different sizes, but rather that it is strongly discouraged. This function is now #[stable] * forget - This function was moved to `mem` and marked #[stable] * bump_box_refcount - This function was removed due to the deprecation of managed boxes as well as its questionable utility. * transmute_mut - This function was previously deprecated, and removed as part of this commit. * transmute_mut_unsafe - This function doesn't serve much of a purpose when it can be achieved with an `as` in safe code, so it was removed. * transmute_lifetime - This function was removed because it is likely a strong indication that code is incorrect in the first place. * transmute_mut_lifetime - This function was removed for the same reasons as `transmute_lifetime` * copy_lifetime - This function was moved to `mem`, but it is marked `#[unstable]` now due to the likelihood of being removed in the future if it is found to not be very useful. * copy_mut_lifetime - This function was also moved to `mem`, but had the same treatment as `copy_lifetime`. * copy_lifetime_vec - This function was removed because it is not used today, and its existence is not necessary with DST (copy_lifetime will suffice). In summary, the cast module was stripped down to these functions, and then the functions were moved to the `mem` module. transmute - #[unstable] transmute_copy - #[stable] forget - #[stable] copy_lifetime - #[unstable] copy_mut_lifetime - #[unstable] [breaking-change]
2014-05-10initial port of the exchange allocator to jemallocDaniel Micay-3/+6
In stage0, all allocations are 8-byte aligned. Passing a size and alignment to free is not yet implemented everywhere (0 size and 8 align are used as placeholders). Fixing this is part of #13994. Closes #13616
2014-05-06librustc: Remove `~EXPR`, `~TYPE`, and `~PAT` from the language, exceptPatrick Walton-7/+9
for `~str`/`~[]`. Note that `~self` still remains, since I forgot to add support for `Box<self>` before the snapshot. How to update your code: * Instead of `~EXPR`, you should write `box EXPR`. * Instead of `~TYPE`, you should write `Box<Type>`. * Instead of `~PATTERN`, you should write `box PATTERN`. [breaking-change]
2014-05-05std: deprecate cast::transmute_mut.Huon Wilson-1/+1
Turning a `&T` into an `&mut T` carries a large risk of undefined behaviour, and needs to be done very very carefully. Providing a convenience function for exactly this task is a bad idea, just tempting people into doing the wrong thing. The right thing is to use types like `Cell`, `RefCell` or `Unsafe`. For memory safety, Rust has that guarantee that `&mut` pointers do not alias with any other pointer, that is, if you have a `&mut T` then that is the only usable pointer to that `T`. This allows Rust to assume that writes through a `&mut T` do not affect the values of any other `&` or `&mut` references. `&` pointers have no guarantees about aliasing or not, so it's entirely possible for the same pointer to be passed into both arguments of a function like fn foo(x: &int, y: &int) { ... } Converting either of `x` or `y` to a `&mut` pointer and modifying it would affect the other value: invalid behaviour. (Similarly, it's undefined behaviour to modify the value of an immutable local, like `let x = 1;`.) At a low-level, the *only* safe way to obtain an `&mut` out of a `&` is using the `Unsafe` type (there are higher level wrappers around it, like `Cell`, `RefCell`, `Mutex` etc.). The `Unsafe` type is registered with the compiler so that it can reason a little about these `&` to `&mut` casts, but it is still up to the user to ensure that the `&mut`s obtained out of an `Unsafe` never alias. (Note that *any* conversion from `&` to `&mut` can be invalid, including a plain `transmute`, or casting `&T` -> `*T` -> `*mut T` -> `&mut T`.) [breaking-change]
2014-05-02Replace most ~exprs with 'box'. #11779Brian Anderson-4/+4
2014-04-23Move task::task() to TaskBuilder::new()Steven Fackler-1/+2
The constructor for `TaskBuilder` is being changed to an associated function called `new` for consistency with the rest of the standard library. Closes #13666 [breaking-change]
2014-04-18Replace all ~"" with "".to_owned()Richo Healey-14/+14
2014-04-10std: Make std::comm return types consistentAlex Crichton-11/+10
There are currently a number of return values from the std::comm methods, not all of which are necessarily completely expressive: Sender::try_send(t: T) -> bool This method currently doesn't transmit back the data `t` if the send fails due to the other end having disconnected. Additionally, this shares the name of the synchronous try_send method, but it differs in semantics in that it only has one failure case, not two (the buffer can never be full). SyncSender::try_send(t: T) -> TrySendResult<T> This method accurately conveys all possible information, but it uses a custom type to the std::comm module with no convenience methods on it. Additionally, if you want to inspect the result you're forced to import something from `std::comm`. SyncSender::send_opt(t: T) -> Option<T> This method uses Some(T) as an "error value" and None as a "success value", but almost all other uses of Option<T> have Some/None the other way Receiver::try_recv(t: T) -> TryRecvResult<T> Similarly to the synchronous try_send, this custom return type is lacking in terms of usability (no convenience methods). With this number of drawbacks in mind, I believed it was time to re-work the return types of these methods. The new API for the comm module is: Sender::send(t: T) -> () Sender::send_opt(t: T) -> Result<(), T> SyncSender::send(t: T) -> () SyncSender::send_opt(t: T) -> Result<(), T> SyncSender::try_send(t: T) -> Result<(), TrySendError<T>> Receiver::recv() -> T Receiver::recv_opt() -> Result<T, ()> Receiver::try_recv() -> Result<T, TryRecvError> The notable changes made are: * Sender::try_send => Sender::send_opt. This renaming brings the semantics in line with the SyncSender::send_opt method. An asychronous send only has one failure case, unlike the synchronous try_send method which has two failure cases (full/disconnected). * Sender::send_opt returns the data back to the caller if the send is guaranteed to fail. This method previously returned `bool`, but then it was unable to retrieve the data if the data was guaranteed to fail to send. There is still a race such that when `Ok(())` is returned the data could still fail to be received, but that's inherent to an asynchronous channel. * Result is now the basis of all return values. This not only adds lots of convenience methods to all return values for free, but it also means that you can inspect the return values with no extra imports (Ok/Err are in the prelude). Additionally, it's now self documenting when something failed or not because the return value has "Err" in the name. Things I'm a little uneasy about: * The methods send_opt and recv_opt are not returning options, but rather results. I felt more strongly that Option was the wrong return type than the _opt prefix was wrong, and I coudn't think of a much better name for these methods. One possible way to think about them is to read the _opt suffix as "optionally". * Result<T, ()> is often better expressed as Option<T>. This is only applicable to the recv_opt() method, but I thought it would be more consistent for everything to return Result rather than one method returning an Option. Despite my two reasons to feel uneasy, I feel much better about the consistency in return values at this point, and I think the only real open question is if there's a better suffix for {send,recv}_opt. Closes #11527
2014-04-08Register new snapshotsAlex Crichton-8/+8
2014-04-08sync: remove unsafe and add Send+Share to Deref (enabled by autoderef vtables)Jim Radford-11/+7
2014-04-04Register new snapshotsAlex Crichton-3/+1
2014-04-03Bump version to 0.11-preBrian Anderson-1/+1
This also changes some of the download links in the documentation to 'nightly'.
2014-04-03auto merge of #13286 : alexcrichton/rust/release, r=brsonbors-1/+1
Merging the 0.10 release into the master branch.
2014-03-31sync: Switch field privacy as necessaryAlex Crichton-57/+61
2014-03-31Bump version to 0.10Alex Crichton-1/+1
2014-03-30auto merge of #13211 : csherratt/rust/arc_fix, r=alexcrichtonbors-4/+38
This is a fix for #13210. fetch_sub returns the old value of the atomic variable, not the new one.
2014-03-30Check that the old value was 1 and not 0 when dropping a Arc value.Colin Sherratt-4/+38
Closed #13210.
2014-03-28Convert most code to new inner attribute syntax.Brian Anderson-12/+12
Closes #2569
2014-03-28Rename Pod into CopyFlavio Percoco-3/+3
Summary: So far, we've used the term POD "Plain Old Data" to refer to types that can be safely copied. However, this term is not consistent with the other built-in bounds that use verbs instead. This patch renames the Pod kind into Copy. RFC: 0003-opt-in-builtin-traits Test Plan: make check Reviewers: cmr Differential Revision: http://phabricator.octayn.net/D3
2014-03-27Fix fallout of removing default boundsAlex Crichton-11/+11
This is all purely fallout of getting the previous commit to compile.
2014-03-24comm: Implement synchronous channelsAlex Crichton-99/+2
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-24sync: Wire up all of the previous commitsAlex Crichton-6/+16
This updates the exports and layout of the crate
2014-03-24sync: Update the arc moduleAlex Crichton-929/+239
This removes the now-outdated MutexArc and RWArc types. These are superseded by Arc<Mutex<T>> and Arc<RWLock<T>>. The only remaining arc is the one true Arc. Additionally, the arc now has weak pointers implemented for it to assist in breaking cycles. This commit brings the arc api up to parity with the sibling Rc api, making them nearly interchangeable for inter and intra task communication.
2014-03-23sync: Introduce new wrapper types for lockingAlex Crichton-0/+816
This introduces new synchronization types which are meant to be the foundational building blocks for sharing data among tasks. The new Mutex and RWLock types have a type parameter which is the internal data that is accessed. Access to the data is all performed through the guards returned, and the guards all have autoderef implemented for easy access.
2014-03-23sync: Rewrite the base primitivesAlex Crichton-617/+406
This commit rewrites the core primitives of the sync library: Mutex, RWLock, and Semaphore. These primitives now have updated, more modernized apis: * Guards are returned instead of locking with closures. All condition variables have moved inside the guards and extraneous methods have been removed. * Downgrading on an rwlock is now done through the guard instead of the rwlock itself. These types are meant to be general locks, not locks of an internal type (for external usage). New types will be introduced for locking shared data.
2014-03-23sync: Move Once to using &selfAlex Crichton-9/+9
Similarly to the rest of the previous commits, this moves the once primitive to using &self instead of &mut self for proper sharing among many threads now.
2014-03-23sync: Move the Mutex type to using &selfAlex Crichton-61/+82
This also uses the Unsafe type for any interior mutability in the type to avoid transmutes.
2014-03-23sync: Move the concurrent queue to using &selfAlex Crichton-9/+10
This commit also lifts it up a level in the module hierarchy in the soon-to-come reorganization of libsync.
2014-03-23auto merge of #13099 : FlaPer87/rust/master, r=huonwbors-5/+1
2014-03-23auto merge of #13093 : Havvy/rust/master, r=sfacklerbors-19/+19
This will make the types more readable in the documentation, since the letters correspond with what you should either be sending or expecting to receive.
2014-03-23Register new snapshotsFlavio Percoco-5/+1
2014-03-22Change types T,U to R (recv), S (sender) in libsync/comm.rsRyan Scheel (Havvy)-19/+19
2014-03-22sync: Remove Freeze / NoFreezeFlavio Percoco-13/+11
2014-03-22Remove outdated and unnecessary std::vec_ng::Vec imports.Huon Wilson-2/+0
(And fix some tests.)
2014-03-21test: Make manual changes to deal with the fallout from removal ofPatrick Walton-24/+28
`~[T]` in test, libgetopts, compiletest, librustdoc, and libnum.
2014-03-20Register new snapshotsAlex Crichton-0/+1
2014-03-20Removing imports of std::vec_ng::VecAlex Crichton-2/+0
It's now in the prelude.
2014-03-20Replace Freeze bounds with Share boundsFlavio Percoco-11/+17
2014-03-20rename std::vec -> std::sliceDaniel Micay-5/+4
Closes #12702
2014-03-15Test fixes and rebase conflictsAlex Crichton-2/+2
This commit switches over the backtrace infrastructure from piggy-backing off the RUST_LOG environment variable to using the RUST_BACKTRACE environment variable (logging is now disabled in libstd).
2014-03-15log: Introduce liblog, the old std::loggingAlex Crichton-0/+3
This commit moves all logging out of the standard library into an external crate. This crate is the new crate which is responsible for all logging macros and logging implementation. A few reasons for this change are: * The crate map has always been a bit of a code smell among rust programs. It has difficulty being loaded on almost all platforms, and it's used almost exclusively for logging and only logging. Removing the crate map is one of the end goals of this movement. * The compiler has a fair bit of special support for logging. It has the __log_level() expression as well as generating a global word per module specifying the log level. This is unfairly favoring the built-in logging system, and is much better done purely in libraries instead of the compiler itself. * Initialization of logging is much easier to do if there is no reliance on a magical crate map being available to set module log levels. * If the logging library can be written outside of the standard library, there's no reason that it shouldn't be. It's likely that we're not going to build the highest quality logging library of all time, so third-party libraries should be able to provide just as high-quality logging systems as the default one provided in the rust distribution. With a migration such as this, the change does not come for free. There are some subtle changes in the behavior of liblog vs the previous logging macros: * The core change of this migration is that there is no longer a physical log-level per module. This concept is still emulated (it is quite useful), but there is now only a global log level, not a local one. This global log level is a reflection of the maximum of all log levels specified. The previously generated logging code looked like: if specified_level <= __module_log_level() { println!(...) } The newly generated code looks like: if specified_level <= ::log::LOG_LEVEL { if ::log::module_enabled(module_path!()) { println!(...) } } Notably, the first layer of checking is still intended to be "super fast" in that it's just a load of a global word and a compare. The second layer of checking is executed to determine if the current module does indeed have logging turned on. This means that if any module has a debug log level turned on, all modules with debug log levels get a little bit slower (they all do more expensive dynamic checks to determine if they're turned on or not). Semantically, this migration brings no change in this respect, but runtime-wise, this will have a perf impact on some code. * A `RUST_LOG=::help` directive will no longer print out a list of all modules that can be logged. This is because the crate map will no longer specify the log levels of all modules, so the list of modules is not known. Additionally, warnings can no longer be provided if a malformed logging directive was supplied. The new "hello world" for logging looks like: #[phase(syntax, link)] extern crate log; fn main() { debug!("Hello, world!"); }
2014-03-15Add rustdoc html crate infoSteven Fackler-0/+3
2014-03-13auto merge of #12861 : huonw/rust/lint-owned-vecs, r=thestingerbors-0/+2
lint: add lint for use of a `~[T]`. This is useless at the moment (since pretty much every crate uses `~[]`), but should help avoid regressions once completely removed from a crate.
2014-03-14lint: add lint for use of a `~[T]`.Huon Wilson-0/+2
This is useless at the moment (since pretty much every crate uses `~[]`), but should help avoid regressions once completely removed from a crate.
2014-03-13std: Rename Chan/Port types and constructorAlex Crichton-254/+159
* 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-12Update users for the std::rand -> librand move.Huon Wilson-12/+16