Commit Graph

180 Commits

Author SHA1 Message Date
LeSeulArtichaut
ac7539c6d1 Deny unsafe ops in unsafe fns, part 3 2020-06-30 17:06:16 +02:00
Dylan DPC
3b41e54799 Rollup merge of #73036 - alexcrichton:update-wasm-fence, r=Mark-Simulacrum
std: Enable atomic.fence emission on wasm32

This commit removes the `#[cfg]` guards in `atomic::fence` on wasm
targets. Since these guards were originally added the upstream wasm
specification for threads gained an `atomic.fence` instruction, so LLVM
no longer panics on these intrinsics.

Although there aren't a ton of tests in-repo for this right now I've
tested locally and all of these fences generate `atomic.fence`
instructions in wasm.

Closes #65687
Closes #72997
2020-06-12 00:05:27 +02:00
Poliorcetics
53984569e2 Only mention u8 and not booleans
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2020-06-06 22:30:09 +02:00
Alex Crichton
05b2d3f7dc std: Enable atomic.fence emission on wasm32
This commit removes the `#[cfg]` guards in `atomic::fence` on wasm
targets. Since these guards were originally added the upstream wasm
specification for threads gained an `atomic.fence` instruction, so LLVM
no longer panics on these intrinsics.

Although there aren't a ton of tests in-repo for this right now I've
tested locally and all of these fences generate `atomic.fence`
instructions in wasm.

Closes #72997
2020-06-05 10:14:53 -07:00
Alexis Bourget
7897f60021 Improve the new documentation to be more precise about the necessary platform's capabilities 2020-06-05 19:07:24 +02:00
Alexis Bourget
817d6a078e Add a **Note**: comment in documentation when the type/method/function is not always available 2020-06-04 22:07:56 +02:00
Yuki Okushi
986c60c78b Rollup merge of #72324 - Amanieu:atomic_minmax, r=dtolnay
Stabilize AtomicN::fetch_min and AtomicN::fetch_max

Some architectures (ARMv8.1 LSE and RISC-V) have specific instructions for atomic min/max which the compiler can only generate through explicit instrinsics.
2020-05-29 15:06:57 +09:00
Amanieu d'Antras
1d7a731f3d Stabilize AtomicN::fetch_min and AtomicN::fetch_max 2020-05-18 15:16:23 +01:00
Steven Fackler
31c8205523 Update src/libcore/sync/atomic.rs
Co-authored-by: Ralf Jung <post@ralfj.de>
2020-05-03 19:36:12 -04:00
Steven Fackler
2ce3f85d46 Tweak and stabilize AtomicN::fetch_update 2020-05-03 07:16:51 -07:00
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