diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2020-07-03 17:17:01 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-03 17:17:01 -0700 |
| commit | 9d0ca3806ff5a3faee2299b6a1a2248d180aae4e (patch) | |
| tree | f4f9136c11ebcffc942c3a2230cbcf3f3ba7f602 /src/libstd | |
| parent | d46de1052d3edcc6538adf6d5fc8f87ab6fcf209 (diff) | |
| parent | 0f1adc8ec812df494df33640c1be147f35e5f6ac (diff) | |
| download | rust-9d0ca3806ff5a3faee2299b6a1a2248d180aae4e.tar.gz rust-9d0ca3806ff5a3faee2299b6a1a2248d180aae4e.zip | |
Rollup merge of #73925 - eduardosm:improve-pr72617-comments, r=RalfJung
Improve comments from #72617, as suggested by RalfJung r? @RalfJung
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/panicking.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index 97d62d958ca..9542e7209b4 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -229,10 +229,10 @@ pub mod panic_count { thread_local! { static LOCAL_PANIC_COUNT: Cell<usize> = Cell::new(0) } // Sum of panic counts from all threads. The purpose of this is to have - // a fast path in `is_zero` (which is used by `panicking`). Access to - // this variable can be always be done with relaxed ordering because - // it is always guaranteed that, if `GLOBAL_PANIC_COUNT` is zero, - // `LOCAL_PANIC_COUNT` will be zero. + // a fast path in `is_zero` (which is used by `panicking`). In any particular + // thread, if that thread currently views `GLOBAL_PANIC_COUNT` as being zero, + // then `LOCAL_PANIC_COUNT` in that thread is zero. This invariant holds before + // and after increase and decrease, but not necessarily during their execution. static GLOBAL_PANIC_COUNT: AtomicUsize = AtomicUsize::new(0); pub fn increase() -> usize { @@ -263,6 +263,12 @@ pub mod panic_count { // Fast path: if `GLOBAL_PANIC_COUNT` is zero, all threads // (including the current one) will have `LOCAL_PANIC_COUNT` // equal to zero, so TLS access can be avoided. + // + // In terms of performance, a relaxed atomic load is similar to a normal + // aligned memory read (e.g., a mov instruction in x86), but with some + // compiler optimization restrictions. On the other hand, a TLS access + // might require calling a non-inlinable function (such as `__tls_get_addr` + // when using the GD TLS model). true } else { is_zero_slow_path() |
