diff options
author | Chris Wailes <chriswailes@google.com> | 2022-12-12 11:43:41 -0800 |
---|---|---|
committer | Jeff Vander Stoep <jeffv@google.com> | 2023-01-18 19:48:52 +0100 |
commit | ff62579fde0625f6c8923b58c9dc848c97c680e6 (patch) | |
tree | c049adb6c0fca041cbb303c8311c1084e4a832cd /src/signal/registry.rs | |
parent | b669ae94fdcda726d88936d028d35187bf41b016 (diff) | |
download | tokio-ff62579fde0625f6c8923b58c9dc848c97c680e6.tar.gz |
Upgrade tokio to 1.23.0
This project was upgraded with external_updater.
Usage: tools/external_updater/updater.sh update rust/crates/tokio
For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md
Test: TreeHugger
Change-Id: Id69553d5e858bddcde0de5b9e72d6bb3c08bafb5
Diffstat (limited to 'src/signal/registry.rs')
-rw-r--r-- | src/signal/registry.rs | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/signal/registry.rs b/src/signal/registry.rs index e0a2df9..e1b3d10 100644 --- a/src/signal/registry.rs +++ b/src/signal/registry.rs @@ -1,10 +1,9 @@ #![allow(clippy::unit_arg)] use crate::signal::os::{OsExtraData, OsStorage}; - use crate::sync::watch; +use crate::util::once_cell::OnceCell; -use once_cell::sync::Lazy; use std::ops; use std::pin::Pin; use std::sync::atomic::{AtomicBool, Ordering}; @@ -152,19 +151,25 @@ impl Globals { } } +fn globals_init() -> Globals +where + OsExtraData: 'static + Send + Sync + Init, + OsStorage: 'static + Send + Sync + Init, +{ + Globals { + extra: OsExtraData::init(), + registry: Registry::new(OsStorage::init()), + } +} + pub(crate) fn globals() -> Pin<&'static Globals> where OsExtraData: 'static + Send + Sync + Init, OsStorage: 'static + Send + Sync + Init, { - static GLOBALS: Lazy<Pin<Box<Globals>>> = Lazy::new(|| { - Box::pin(Globals { - extra: OsExtraData::init(), - registry: Registry::new(OsStorage::init()), - }) - }); - - GLOBALS.as_ref() + static GLOBALS: OnceCell<Globals> = OnceCell::new(); + + Pin::new(GLOBALS.get(globals_init)) } #[cfg(all(test, not(loom)))] @@ -202,7 +207,12 @@ mod tests { registry.broadcast(); // Yield so the previous broadcast can get received - crate::time::sleep(std::time::Duration::from_millis(10)).await; + // + // This yields many times since the block_on task is only polled every 61 + // ticks. + for _ in 0..100 { + crate::task::yield_now().await; + } // Send subsequent signal registry.record_event(0); @@ -232,7 +242,7 @@ mod tests { #[test] fn record_invalid_event_does_nothing() { let registry = Registry::new(vec![EventInfo::default()]); - registry.record_event(42); + registry.record_event(1302); } #[test] |