From e3261440e56ebf576790e4c6f7f125a6c8759659 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Tue, 29 Oct 2019 22:16:11 -0700 Subject: [PATCH] timer: inline CachePadded type (#1706) --- tokio/Cargo.toml | 3 +-- tokio/src/timer/timer/entry.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index a85f0c7a5..ee32b954a 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -65,7 +65,7 @@ signal = [ ] sync = ["fnv"] tcp = ["io", "net-driver"] -timer = ["crossbeam-utils", "slab"] +timer = ["slab"] udp = ["io", "net-driver"] uds = ["io", "net-driver", "mio-uds", "libc"] process = [ @@ -90,7 +90,6 @@ futures-util-preview = { version = "=0.3.0-alpha.19", features = ["sink", "chann # Everything else is optional... bytes = { version = "0.4", optional = true } crossbeam-channel = { version = "0.3.8", optional = true } -crossbeam-utils = { version = "0.6.0", optional = true } fnv = { version = "1.0.6", optional = true } iovec = { version = "0.1", optional = true } lazy_static = { version = "1.0.2", optional = true } diff --git a/tokio/src/timer/timer/entry.rs b/tokio/src/timer/timer/entry.rs index f4f43e6bf..7c653ad90 100644 --- a/tokio/src/timer/timer/entry.rs +++ b/tokio/src/timer/timer/entry.rs @@ -3,7 +3,6 @@ use crate::timer::atomic::AtomicU64; use crate::timer::timer::{HandlePriv, Inner}; use crate::timer::Error; -use crossbeam_utils::CachePadded; use std::cell::UnsafeCell; use std::ptr; use std::sync::atomic::AtomicBool; @@ -108,7 +107,7 @@ const ERROR: u64 = u64::MAX; impl Entry { pub(crate) fn new(deadline: Instant, duration: Duration) -> Entry { Entry { - time: CachePadded::new(UnsafeCell::new(Time { deadline, duration })), + time: CachePadded(UnsafeCell::new(Time { deadline, duration })), inner: None, waker: AtomicWaker::new(), state: AtomicU64::new(0), @@ -122,13 +121,13 @@ impl Entry { /// Only called by `Registration` pub(crate) fn time_ref(&self) -> &Time { - unsafe { &*self.time.get() } + unsafe { &*self.time.0.get() } } /// Only called by `Registration` #[allow(clippy::mut_from_ref)] // https://github.com/rust-lang/rust-clippy/issues/4281 pub(crate) unsafe fn time_mut(&self) -> &mut Time { - &mut *self.time.get() + &mut *self.time.0.get() } /// Returns `true` if the `Entry` is currently associated with a timer @@ -390,3 +389,8 @@ impl Drop for Entry { unsafe impl Send for Entry {} unsafe impl Sync for Entry {} + +#[cfg_attr(target_arch = "x86_64", repr(align(128)))] +#[cfg_attr(not(target_arch = "x86_64"), repr(align(64)))] +#[derive(Debug)] +struct CachePadded(T);