()
| 476 | }; |
| 477 | |
| 478 | pub(crate) fn install_builtin_hooks() { |
| 479 | // We could in theory remove this and replace it with a single AtomicBool. |
| 480 | static INSTALL_BUILTIN: Once = Once::new(); |
| 481 | |
| 482 | // This static makes sure that we only run once, if we wouldn't have this guard we would |
| 483 | // deadlock, as `install_debug_hook` calls `install_builtin_hooks`, and according to the |
| 484 | // docs: |
| 485 | // |
| 486 | // > If the given closure recursively invokes call_once on the same Once instance the exact |
| 487 | // > behavior is not specified, allowed outcomes are a panic or a deadlock. |
| 488 | // |
| 489 | // This limitation is not present for the implementation from the spin crate, but for |
| 490 | // simplicity and readability the extra guard is kept. |
| 491 | static INSTALL_BUILTIN_RUNNING: AtomicBool = AtomicBool::new(false); |
| 492 | |
| 493 | // This has minimal overhead, as `Once::call_once` calls `.is_completed` as the short path |
| 494 | // we just move it out here, so that we're able to check `INSTALL_BUILTIN_RUNNING` |
| 495 | if INSTALL_BUILTIN.is_completed() || INSTALL_BUILTIN_RUNNING.load(Ordering::Acquire) { |
| 496 | return; |
| 497 | } |
| 498 | |
| 499 | INSTALL_BUILTIN.call_once(|| { |
| 500 | INSTALL_BUILTIN_RUNNING.store(true, Ordering::Release); |
| 501 | |
| 502 | Report::install_debug_hook::<Location>(location); |
| 503 | |
| 504 | #[cfg(feature = "backtrace")] |
| 505 | Report::install_debug_hook::<Backtrace>(backtrace); |
| 506 | |
| 507 | #[cfg(feature = "spantrace")] |
| 508 | Report::install_debug_hook::<SpanTrace>(span_trace); |
| 509 | }); |
| 510 | } |
| 511 | |
| 512 | fn location(location: &Location<'static>, context: &mut HookContext<Location<'static>>) { |
| 513 | context.push_body(LocationAttachment::new(location, context.color_mode()).to_string()); |
no test coverage detected