-
Notifications
You must be signed in to change notification settings - Fork 1k
[naga]: Switch off of LazyLock
to once_cell::racy::OnceBox
#7587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the idea of the change is fine, but I would rather not have the unsafe be our responsibility - once_cell::racy::OnceBox
exists and is already in-tree - can we build our RacyLock on top of that, we can do it in entirely safe code?
Oh I didn't realise that was the case, and I wasn't familiar with |
Switched to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nits
Co-Authored-By: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
Co-Authored-By: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
Co-Authored-By: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
LazyLock
to a custom RacyLock
LazyLock
to once_cell::racy::OnceBox
Connections
Description
LazyLock
,RacyLock
, which usesAtomicPtr
internally. This type is a drop-in replacement forLazyLock
, but it trades in blocking for potentially leaking the initialized value in cases where multiple threads attempt to initialize. The type is public but in a private module to prevent external use.LazyLock
and replaced them withRacyLock
.hlsl_out
,wgsl_out
, andmsl_out
from theextern crate std;
statement, decoupling those features from explicitstd
usage.Testing
Squash or Rebase?
Squash
Checklist
cargo fmt
.RunN/Ataplo format
.cargo clippy --tests
. If applicable, add:--target wasm32-unknown-unknown
cargo xtask test
to run tests.If this contains user-facing changes, add aN/ACHANGELOG.md
entry.Notes
This addition includes twounsafe
blocks in order to dereference the pointer stored within an internalAtomicPtr
. I considered this preferable to bringing in a 3rd party dependency, such asspin
.I also chose to not offer a feature to switch back to
std::sync::LazyLock
, since such a feature would increase Naga's complexity, and risk stagnatingunsafe
code.