From 8d2e3bc575f51815ae7319f1e43fe6c7d664e6e4 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Sat, 12 Sep 2020 22:58:58 +0200 Subject: sync: add const constructors to RwLock, Notify, and Semaphore (#2833) * Add const constructors to `RwLock`, `Notify`, and `Semaphore`. Referring to the types in `tokio::sync`. Also add `const` to `new` for the remaining atomic integers in `src/loom` and `UnsafeCell`. Builds upon previous work in #2790 Closes #2756 --- tokio/src/sync/notify.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tokio/src/sync/notify.rs') diff --git a/tokio/src/sync/notify.rs b/tokio/src/sync/notify.rs index 74c69e50..c69e2b07 100644 --- a/tokio/src/sync/notify.rs +++ b/tokio/src/sync/notify.rs @@ -170,6 +170,24 @@ impl Notify { } } + /// Create a new `Notify`, initialized without a permit. + /// + /// # Examples + /// + /// ``` + /// use tokio::sync::Notify; + /// + /// static NOTIFY: Notify = Notify::const_new(); + /// ``` + #[cfg(all(feature = "parking_lot", not(all(loom, test))))] + #[cfg_attr(docsrs, doc(cfg(feature = "parking_lot")))] + pub const fn const_new() -> Notify { + Notify { + state: AtomicU8::new(0), + waiters: Mutex::const_new(LinkedList::new()), + } + } + /// Wait for a notification. /// /// Equivalent to: -- cgit v1.2.3