@@ -229,10 +229,10 @@ pub mod panic_count {
229
229
thread_local ! { static LOCAL_PANIC_COUNT : Cell <usize > = Cell :: new( 0 ) }
230
230
231
231
// Sum of panic counts from all threads. The purpose of this is to have
232
- // a fast path in `is_zero` (which is used by `panicking`). Access to
233
- // this variable can be always be done with relaxed ordering because
234
- // it is always guaranteed that, if `GLOBAL_PANIC_COUNT` is zero,
235
- // `LOCAL_PANIC_COUNT` will be zero .
232
+ // a fast path in `is_zero` (which is used by `panicking`). In any particular
233
+ // thread, if that thread currently views `GLOBAL_PANIC_COUNT` as being zero,
234
+ // then `LOCAL_PANIC_COUNT` in that thread is zero. This invariant holds before
235
+ // and after increase and decrease, but not necessarily during their execution .
236
236
static GLOBAL_PANIC_COUNT : AtomicUsize = AtomicUsize :: new ( 0 ) ;
237
237
238
238
pub fn increase ( ) -> usize {
@@ -263,6 +263,12 @@ pub mod panic_count {
263
263
// Fast path: if `GLOBAL_PANIC_COUNT` is zero, all threads
264
264
// (including the current one) will have `LOCAL_PANIC_COUNT`
265
265
// equal to zero, so TLS access can be avoided.
266
+ //
267
+ // In terms of performance, a relaxed atomic load is similar to a normal
268
+ // aligned memory read (e.g., a mov instruction in x86), but with some
269
+ // compiler optimization restrictions. On the other hand, a TLS access
270
+ // might require calling a non-inlinable function (such as `__tls_get_addr`
271
+ // when using the GD TLS model).
266
272
true
267
273
} else {
268
274
is_zero_slow_path ( )
0 commit comments