Commit Graph

170 Commits

Author SHA1 Message Date
Tomasz Miąsko af0d6fc007 Use copy bound in atomic operations to generate simpler MIR 2020-03-18 00:47:08 +01:00
LeSeulArtichaut abcbf7c09d Document stable versions of f32 and f64 intrinsics
Fix links
2020-02-11 22:08:20 +01:00
Phoebe Bell 022a7de26f Add SAFETY comment for atomic example 2020-01-16 19:26:02 -08:00
Phoebe Bell ca2fae8edb Elaborate on SAFETY comments 2020-01-16 18:32:21 -08:00
Phoebe Bell 19fdc6e091 Document unsafe blocks in core::{cell, str, sync} 2020-01-16 18:26:14 -08:00
Aleksey Kladov b25eeef88d Add more nuanced advice about spin_loop_hint 2020-01-05 20:37:22 +01:00
Aleksey Kladov 4d04b0b0fe Remove wrong advice about spin locks from spin_loop_hint docs
Using a pure spin lock for a critical section in a preemptable thread
is always wrong, however short the critical section may be. The thread
might be preempted, which will cause all other threads to hammer
busily at the core for the whole quant. Moreover, if threads have
different priorities, this might lead to a priority inversion problem
and a deadlock. More generally, a spinlock is not more efficient than
a well-written mutex, which typically does several spin iterations at
the start anyway.

The advise about UP vs SMP is also irrelevant in the context of
preemptive threads.
2020-01-02 04:02:48 +01:00
Mark Rousskov a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Mark Rousskov 82184440ec Propagate cfg bootstrap 2019-12-18 12:16:19 -05:00
Lzu Tao 7bf55f4aa5 use Self alias in place of macros 2019-12-15 13:55:10 +00:00
Oliver Scherer 0b47ba7019 The constness of 128 bit atomics will be stabilized together with the atomics 2019-12-13 13:28:55 +01:00
Oliver Scherer f12affef12 Address review comments 2019-12-13 11:27:02 +01:00
Oliver Scherer 5e17e39881 Require stable/unstable annotations for the constness of all stable functions with a const modifier 2019-12-13 11:27:02 +01:00
Mazdak Farrokhzad 9a72b42a6d Rollup merge of #67005 - andrewbanchich:master, r=joshtriplett
capitalize Rust

Capitalize "Rust" in docs.
2019-12-05 19:03:13 +01:00
Andrew Banchich 1fa948f4cc capitalize Rust 2019-12-03 19:11:53 -05:00
Mazdak Farrokhzad 123406cac7 Rollup merge of #66705 - pitdicker:atomic_mut_ptr, r=KodrAus
Atomic as_mut_ptr

I encountered the following pattern a few times: In Rust we use some atomic type like `AtomicI32`, and an FFI interface exposes this as `*mut i32` (or some similar `libc` type).

It was not obvious to me if a just transmuting a pointer to the atomic was acceptable, or if this should use a cast that goes through an `UnsafeCell`. See https://github.com/rust-lang/rust/issues/66136#issuecomment-557802477

Transmuting the pointer directly:
```rust
let atomic = AtomicI32::new(1);
let ptr = &atomic as *const AtomicI32 as *mut i32;
unsafe {
    ffi(ptr);
}
```

A dance with `UnsafeCell`:
```rust
let atomic = AtomicI32::new(1);
unsafe {
    let ptr = (&*(&atomic as *const AtomicI32 as *const UnsafeCell<i32>)).get();
    ffi(ptr);
}
```

Maybe in the end both ways could be valid. But why not expose a direct method to get a pointer from the standard library?

An `as_mut_ptr` method on atomics can be safe, because only the use of the resulting pointer is where things can get unsafe. I documented its use for FFI, and "Doing non-atomic reads and writes on the resulting integer can be a data race."

The standard library could make use this method in a few places in the WASM module.

cc @RalfJung as you answered my original question.
2019-11-30 16:56:47 +01:00
Paul Dicker d34090a10a Fill tracking issue 2019-11-30 12:58:15 +01:00
Paul Dicker 4843173a00 Document why as_mut_ptr is safe 2019-11-30 12:57:50 +01:00
Paul Dicker 3b1c742e23 Add as_mut_ptr method to atomic types. 2019-11-23 17:24:14 +01:00
Mark Rousskov 997feacddd Snap cfgs 2019-11-12 16:36:57 -05:00
Oliver Scherer 02f9167f94 Have tidy ensure that we document all unsafe blocks in libcore 2019-11-06 11:04:42 +01:00
Mazdak Farrokhzad 7c20a8ddb8 Rollup merge of #65214 - Amanieu:cfg_atomic, r=alexcrichton
Split non-CAS atomic support off into target_has_atomic_load_store

This PR implements my proposed changes in https://github.com/rust-lang/rust/issues/32976#issuecomment-518542029 by removing `target_has_atomic = "cas"` and splitting `target_has_atomic` into two separate `cfg`s:

* `target_has_atomic = 8/16/32/64/128`: This indicates the largest width that the target can atomically CAS (which implies support for all atomic operations).
* ` target_has_atomic_load_store = 8/16/32/64/128`: This indicates the largest width that the target can support loading or storing atomically (but may not support CAS).

cc #32976

r? @alexcrichton
2019-10-13 19:17:04 +02:00
Ralf Jung d6ab45d264 fix link targets 2019-10-12 20:09:24 +02:00
Ralf Jung f36355070e it's C++20 2019-10-12 17:57:31 +02:00
Ralf Jung a2b2362ce7 do not reference LLVM for our concurrency memory model 2019-10-12 16:23:39 +02:00
Amanieu d'Antras dfe76a1093 Split non-CAS atomic support off into target_has_atomic_load_store 2019-10-08 20:34:30 +01:00
Tyler Mandry 05d93a7d06 Rollup merge of #64348 - arnohaase:pr_documentation_spin_loop_hint, r=alexcrichton
PR: documentation spin loop hint

The documentation for 'spin loop hint' explains that yield is better if the lock holder is running on the same CPU. I suggest that 'CPU or core' would be clearer.
2019-09-18 10:58:05 -07:00
Arno Haase eb48b5d983 broken hyperlinks in documentation 2019-09-18 12:31:34 +02:00
Arno Haase f4f136e67b newly phrased documentation for spin loop hints 2019-09-17 12:09:07 +02:00
Arno Haase 51c49e2573 fixed linter error 2019-09-10 14:25:40 +02:00
Arno Haase 7ad44c7c9c documentation for AtomicPtr CAS operations 2019-09-10 14:18:16 +02:00
Arno Haase 356b4c81a0 documentation enhancement for 'spin loop hint': replace 'CPU' with 'CPU or core' 2019-09-10 14:03:31 +02:00
Lzu Tao f60b5f1bc7 Remove unneeded feature attr from atomic integers doctests 2019-06-04 13:24:39 +00:00
Mazdak Farrokhzad dbfbadeac4 libcore: deny more... 2019-04-19 01:37:12 +02:00
Taiki Endo 360432f1e8 libcore => 2018 2019-04-18 14:47:35 +09:00
Christian ab3b657373 Updated the documentation of core::hints::spin_loop and core::sync::spin_loop_hint 2019-04-03 10:54:07 +02:00
Mark Rousskov 2870015b7b Bootstrap compiler update for 1.35 release 2019-03-02 09:05:34 -07:00
Mahmut Bulut 99d67ca3b8 Destabilize fixed-width const defined atomic integers
* With this PR 1.34.0 onwards const declarations of atomic integers will be
  unstable.
2019-02-21 13:57:51 +01:00
Oliver Scherer 4056b575e2 Add suggestions to deprecation lints 2019-01-30 17:49:04 +01:00
Mark Rousskov 7a58c6d1de Replace deprecated ATOMIC_INIT consts 2019-01-26 15:27:38 -07:00
Alex Crichton 14b36fb15a std: Stabilize fixed-width integer atomics
This commit stabilizes the `Atomic{I,U}{8,16,32,64}` APIs in the
`std::sync::atomic` and `core::sync::atomic` modules. Proposed in #56753
and tracked in #32976 this feature has been unstable for quite some time
and is hopefully ready to go over the finish line now!

The API is being stabilized as-is. The API of `AtomicU8` and friends
mirrors that of `AtomicUsize`. A list of changes made here are:

* A portability documentation section has been added to describe the
  current state of affairs.
* Emulation of smaller-size atomics with larger-size atomics has been
  documented.
* As an added bonus, `ATOMIC_*_INIT` is now scheduled for deprecation
  across the board in 1.34.0 now that `const` functions can be invoked
  in statics.

Note that the 128-bit atomic types are omitted from this stabilization
explicitly. They have far less platform support than the other atomic
types, and will likely require further discussion about their best
location.

Closes #32976
Closes #56753
2019-01-25 11:48:10 -08:00
Clar Fon 24ca530526 Move spin_loop_hint to core::hint module 2019-01-15 16:44:28 -05:00
Mark Rousskov 2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Pietro Albini b08a52c8d4 Rollup merge of #56881 - Amanieu:ordering_eq, r=alexcrichton
Implement Eq, PartialEq and Hash for atomic::Ordering

r? @alexcrichton
2018-12-19 11:47:11 +01:00
Amanieu d'Antras cd70d7df7b Implement Eq, PartialEq and Hash for atomic::Ordering 2018-12-16 16:37:18 +00:00
Mazdak Farrokhzad 443881a37b Rollup merge of #53506 - phungleson:fix-from-docs-atomic, r=KodrAus
Documentation for impl From for AtomicBool and other Atomic types

As part of issue #51430 (cc @skade).

The impl is very simple, so not sure if we need to go into any details.
2018-12-16 14:08:13 +01:00
Alex Crichton cf47a19305 Bump to 1.33.0
* Update bootstrap compiler
* Update version to 1.33.0
* Remove some `#[cfg(stage0)]` annotations

Actually updating the version number is blocked on updating Cargo
2018-12-12 08:09:26 -08:00
Son 94c1c7328a Documentation for impl From for AtomicBool and other Atomic types 2018-12-12 09:41:12 +11:00
Michal 'vorner' Vaner cc63bd47ef atomic::Ordering: Get rid of misleading parts of intro
Remove the parts of atomic::Ordering's intro that wrongly claimed that
SeqCst prevents all reorderings around it.

Closes #55196
2018-11-18 11:12:01 +01:00
Simonas Kazlauskas 99f7dc451f Do not Atomic{I,U}128 in stage0 2018-11-05 18:54:17 +02:00