Skip to content

Conversation

@tamird
Copy link
Contributor

@tamird tamird commented Feb 3, 2026

Replace ad-hoc atomic lazy caches with shared lazy helpers in the Linux/Android fallback, NetBSD, RDRAND, and RNDR backends. Add LazyPtr alongside LazyUsize and LazyBool so pointer and boolean caches use the same initialization contract.

This reduces duplicated cache logic and keeps backend probing/fallback semantics aligned while preserving the existing retry-until-cached behavior.

Replace ad-hoc atomic lazy caches with shared lazy helpers in the
Linux/Android fallback, NetBSD, RDRAND, and RNDR backends. Add `LazyPtr`
alongside `LazyUsize` and `LazyBool` so pointer and boolean caches use
the same initialization contract.

This reduces duplicated cache logic and keeps backend probing/fallback
semantics aligned while preserving the existing retry-until-cached
behavior.
Copy link
Member

@newpavlov newpavlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to keep the NonNull stuff.


/// Lazily initializes a cached bool; reuses `LazyUsize` to avoid sentinel
/// issues with `AtomicBool`.
#[allow(dead_code)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use #![allow(dead_code)] for the whole module.


// Identical to LazyUsize except with bool instead of usize.
lazy_atomic!(LazyUsize, AtomicUsize, usize, usize::MAX);
lazy_atomic!(LazyPtr<T>, AtomicPtr<T>, *mut T, ptr::dangling_mut());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use dangligng pointer instead of null?

struct LazyUsize(AtomicUsize);
macro_rules! lazy_atomic {
($name:ident $(<$($gen:ident),+>)?, $atomic:ty, $value:ty, $uninit:expr) => {
// This structure represents a lazily initialized static usize value. Useful
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc is not correct for LazyPtr. Probably better to just move the description to the module-level docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants