Amanieu / parking_lot

Compact and efficient synchronization primitives for Rust. Also provides an API for creating custom synchronization primitives.
Apache License 2.0
2.76k stars 217 forks source link

Add a method to Once to create an already-done Once #441

Open PlasmaPower opened 6 months ago

PlasmaPower commented 6 months ago

I'm looking at using Once as a sort of dirty flag, and it'd be useful to have a method to create a Once that's already done (i.e. marked as already clean). E.g.:

impl Once {
    #[inline]
    pub const fn new_done() -> Once {
        Once(AtomicU8::new(DONE_BIT))
    }
Amanieu commented 6 months ago

The method should be named new_completed for consistency with is_completed. Please send a PR to the standard library as well if you plan on implementing this. I'm happy to accept a PR here.