fish-shell/fish-rust
Mahmoud Al-Qudsi 59fe124c40 builtins/random: Don't lock the mutex unnecessarily
The mutex was being locked from the very start, before it was needed and
possibly before it would be needed.

Also rename the static global to stick to rust naming conventions.

Note that `once_cell::sync::Lazy<T>` actually internally uses its own lock
around the value, but in this case it's insufficient because `SmallRng` doesn't
implement `SeedableRng` so we can't reseed it with only an `&mut` reference and
must instead replace its value.

We probably *could* still use `Lazy<SmallRng>` directly and then rely on
`std::mem::swap()` to replace the contents of the shared global static without
reassigning the variable directly with a new `SmallRng` instance, but I'm not
sure that's a great idea. This is just a built-in, there's no real harm in
locking twice (especially while fish remains essentially single-threaded).
2023-02-19 16:54:50 -06:00
..
src builtins/random: Don't lock the mutex unnecessarily 2023-02-19 16:54:50 -06:00
widestring-suffix Initial Rust commit 2023-02-02 19:34:47 -07:00
build.rs Port fd_monitor (and its needed components) 2023-02-19 15:42:03 -06:00
Cargo.lock Port random to rust 2023-02-19 21:01:46 +01:00
Cargo.toml Port random to rust 2023-02-19 21:01:46 +01:00