From 4ccf596d96ca9b6166317db5aab8757e838712f4 Mon Sep 17 00:00:00 2001 From: Iban Eguia Moraza Date: Fri, 27 Nov 2020 17:08:44 +0100 Subject: [PATCH 1/3] Replace lazy_static with once_cell --- tokio/Cargo.toml | 8 ++++---- tokio/src/process/unix/mod.rs | 5 ++--- tokio/src/signal/registry.rs | 12 +++++------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index c658fc44294..31134f0e76a 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -50,7 +50,7 @@ io-util = ["memchr", "bytes"] io-std = [] macros = ["tokio-macros"] net = [ - "lazy_static", + "once_cell", "libc", "mio/os-poll", "mio/os-util", @@ -60,7 +60,7 @@ net = [ ] process = [ "bytes", - "lazy_static", + "once_cell", "libc", "mio/os-poll", "mio/os-util", @@ -75,7 +75,7 @@ rt-multi-thread = [ "rt", ] signal = [ - "lazy_static", + "once_cell", "libc", "mio/os-poll", "mio/uds", @@ -96,7 +96,7 @@ pin-project-lite = "0.2.0" # Everything else is optional... bytes = { version = "0.6.0", optional = true } futures-core = { version = "0.3.0", optional = true } -lazy_static = { version = "1.4.0", optional = true } +once_cell = { version = "1.5.2", optional = true } memchr = { version = "2.2", optional = true } mio = { version = "0.7.6", optional = true } num_cpus = { version = "1.8.0", optional = true } diff --git a/tokio/src/process/unix/mod.rs b/tokio/src/process/unix/mod.rs index 966c2a2887b..c07d751562f 100644 --- a/tokio/src/process/unix/mod.rs +++ b/tokio/src/process/unix/mod.rs @@ -36,6 +36,7 @@ use crate::signal::unix::{signal, Signal, SignalKind}; use mio::event::Source; use mio::unix::SourceFd; +use once_cell::sync::Lazy; use std::fmt; use std::fs::File; use std::future::Future; @@ -62,9 +63,7 @@ impl Kill for StdChild { } } -lazy_static::lazy_static! { - static ref ORPHAN_QUEUE: OrphanQueueImpl = OrphanQueueImpl::new(); -} +static ORPHAN_QUEUE: Lazy> = Lazy::new(|| OrphanQueueImpl::new()); pub(crate) struct GlobalOrphanQueue; diff --git a/tokio/src/signal/registry.rs b/tokio/src/signal/registry.rs index 5d6f608c607..bfa11d731d8 100644 --- a/tokio/src/signal/registry.rs +++ b/tokio/src/signal/registry.rs @@ -4,7 +4,7 @@ use crate::signal::os::{OsExtraData, OsStorage}; use crate::sync::mpsc::Sender; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::ops; use std::pin::Pin; use std::sync::atomic::{AtomicBool, Ordering}; @@ -165,12 +165,10 @@ where OsExtraData: 'static + Send + Sync + Init, OsStorage: 'static + Send + Sync + Init, { - lazy_static! { - static ref GLOBALS: Pin> = Box::pin(Globals { - extra: OsExtraData::init(), - registry: Registry::new(OsStorage::init()), - }); - } + static GLOBALS: Lazy>> = Lazy::new(|| Box::pin(Globals { + extra: OsExtraData::init(), + registry: Registry::new(OsStorage::init()), + })); GLOBALS.as_ref() } From 73f41644d3b6055249f60d0a5dea8d2b6fac3f95 Mon Sep 17 00:00:00 2001 From: Iban Eguia Moraza Date: Fri, 27 Nov 2020 17:28:49 +0100 Subject: [PATCH 2/3] Ran rustfmt --- tokio/src/signal/registry.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tokio/src/signal/registry.rs b/tokio/src/signal/registry.rs index bfa11d731d8..55ee8c53263 100644 --- a/tokio/src/signal/registry.rs +++ b/tokio/src/signal/registry.rs @@ -165,10 +165,12 @@ where OsExtraData: 'static + Send + Sync + Init, OsStorage: 'static + Send + Sync + Init, { - static GLOBALS: Lazy>> = Lazy::new(|| Box::pin(Globals { - extra: OsExtraData::init(), - registry: Registry::new(OsStorage::init()), - })); + static GLOBALS: Lazy>> = Lazy::new(|| { + Box::pin(Globals { + extra: OsExtraData::init(), + registry: Registry::new(OsStorage::init()), + }) + }); GLOBALS.as_ref() } From 5f405832822e600945ce11a799e9252e22826b0c Mon Sep 17 00:00:00 2001 From: Iban Eguia Moraza Date: Thu, 3 Dec 2020 15:38:59 +0100 Subject: [PATCH 3/3] Fixed feedback --- tokio/Cargo.toml | 1 - tokio/src/process/unix/mod.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index 31134f0e76a..e1a963beb58 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -50,7 +50,6 @@ io-util = ["memchr", "bytes"] io-std = [] macros = ["tokio-macros"] net = [ - "once_cell", "libc", "mio/os-poll", "mio/os-util", diff --git a/tokio/src/process/unix/mod.rs b/tokio/src/process/unix/mod.rs index c07d751562f..3608b9f1bc0 100644 --- a/tokio/src/process/unix/mod.rs +++ b/tokio/src/process/unix/mod.rs @@ -63,7 +63,7 @@ impl Kill for StdChild { } } -static ORPHAN_QUEUE: Lazy> = Lazy::new(|| OrphanQueueImpl::new()); +static ORPHAN_QUEUE: Lazy> = Lazy::new(OrphanQueueImpl::new); pub(crate) struct GlobalOrphanQueue;