about summary refs log tree commit diff
path: root/library/std/src/sys/sync/once
AgeCommit message (Collapse)AuthorLines
2025-09-03thread parking: fix docs and examplesRalf Jung-1/+3
2025-08-16library: Migrate from `cfg_if` to `cfg_select`Josh Triplett-6/+8
Migrate the standard library from using the external `cfg_if` crate to using the now-built-in `cfg_select` macro. This does not yet eliminate the dependency from `library/std/Cargo.toml`, because while the standard library itself no longer uses `cfg_if`, it also incorporates the `backtrace` crate, which does. Migration assisted by the following vim command (after selecting the full `cfg_if!` invocation): ``` '<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e ``` This is imperfect, but substantially accelerated the process. This prompts for confirmation on the `} else {` since that can also appear inside one of the arms. This also requires manual intervention to handle any multi-line conditions.
2025-07-13Add comment why we use zero for COMPLETEOrson Peters-1/+4
2025-07-13Use zero for initialized Once stateOrson Peters-8/+8
2025-04-27use generic Atomic type where possibleChristopher Durham-5/+5
in core/alloc/std only for now, and ignoring test files Co-authored-by: Pavel Grigorenko <GrigorenkoPV@ya.ru>
2025-01-02Move some things to `std::sync::poison` and reexport them in `std::sync`Pavel Grigorenko-3/+3
2024-11-27update cfgsBoxy-2/+0
2024-11-18std: allow after-main use of synchronization primitivesjoboet-4/+5
By creating an unnamed thread handle when the actual one has already been destroyed, synchronization primitives using thread parking can be used even outside the Rust runtime. This also fixes an inefficiency in the queue-based `RwLock`: if `thread::current` was not initialized yet, it will create a new handle on every parking attempt without initializing `thread::current`. The private `current_or_unnamed` function introduced here fixes this.
2024-10-28we can now enable the 'const stable fn must be stable' checkRalf Jung-1/+1
2024-10-25Re-do recursive const stability checksRalf Jung-1/+1
Fundamentally, we have *three* disjoint categories of functions: 1. const-stable functions 2. private/unstable functions that are meant to be callable from const-stable functions 3. functions that can make use of unstable const features This PR implements the following system: - `#[rustc_const_stable]` puts functions in the first category. It may only be applied to `#[stable]` functions. - `#[rustc_const_unstable]` by default puts functions in the third category. The new attribute `#[rustc_const_stable_indirect]` can be added to such a function to move it into the second category. - `const fn` without a const stability marker are in the second category if they are still unstable. They automatically inherit the feature gate for regular calls, it can now also be used for const-calls. Also, several holes in recursive const stability checking are being closed. There's still one potential hole that is hard to avoid, which is when MIR building automatically inserts calls to a particular function in stable functions -- which happens in the panic machinery. Those need to *not* be `rustc_const_unstable` (or manually get a `rustc_const_stable_indirect`) to be sure they follow recursive const stability. But that's a fairly rare and special case so IMO it's fine. The net effect of this is that a `#[unstable]` or unmarked function can be constified simply by marking it as `const fn`, and it will then be const-callable from stable `const fn` and subject to recursive const stability requirements. If it is publicly reachable (which implies it cannot be unmarked), it will be const-unstable under the same feature gate. Only if the function ever becomes `#[stable]` does it need a `#[rustc_const_unstable]` or `#[rustc_const_stable]` marker to decide if this should also imply const-stability. Adding `#[rustc_const_unstable]` is only needed for (a) functions that need to use unstable const lang features (including intrinsics), or (b) `#[stable]` functions that are not yet intended to be const-stable. Adding `#[rustc_const_stable]` is only needed for functions that are actually meant to be directly callable from stable const code. `#[rustc_const_stable_indirect]` is used to mark intrinsics as const-callable and for `#[rustc_const_unstable]` functions that are actually called from other, exposed-on-stable `const fn`. No other attributes are required.
2024-10-17Abstract the state type for futexesPaul Menage-14/+13
In the same way that we expose SmallAtomic and SmallPrimitive to allow Windows to use a value other than an AtomicU32 for its futex state, this patch switches the primary futex state type from AtomicU32 to futex::Atomic. The futex::Atomic type should be usable as an atomic value with underlying primitive type equal to futex::Primitive. This allows supporting the futex API on systems where the underlying kernel futex implementation requires more state than simply an AtomicU32. All in-tree futex implementations simply define {Atomic,Primitive} directly as {AtomicU32,u32}.
2024-09-17Implement ACP 429: add `Lazy{Cell,Lock}::get[_mut]` and `force_mut`Chayim Refael Friedman-0/+27
In the implementation of `force_mut`, I chose performance over safety. For `LazyLock` this isn't really a choice; the code has to be unsafe. But for `LazyCell`, we can have a full-safe implementation, but it will be a bit less performant, so I went with the unsafe approach.
2024-07-31std: fix busy-waiting in `Once::wait_force`, add more testsjoboet-4/+8
2024-07-31std: implement the `once_wait` featurejoboet-94/+178
2024-07-29Reformat `use` declarations.Nicholas Nethercote-7/+3
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-17Auto merge of #125942 - timokroeger:windows-once-futex, r=ChrisDentonbors-0/+1
Windows: Use futex implementation for `Once` Keep the queue implementation for win7. Inspired by PR #121956 <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> -->
2024-07-17Prevent double reference in generic futexChris Denton-1/+1
2024-06-04Windows: Use futex implementation for `Once`Timo Kröger-0/+1
Keep the queue implementation for win7. Inspired by PR #121956
2024-03-12std: move `Once` implementations to `sys`joboet-0/+576