diff --git a/Cargo.lock b/Cargo.lock index a4240eb58..8a8010961 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -222,6 +222,7 @@ version = "0.1.2" dependencies = [ "console-api", "crossbeam-channel", + "crossbeam-utils", "futures", "hdrhistogram", "humantime", @@ -258,9 +259,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.5" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" +checksum = "b5e5bed1f1c269533fa816a0a5492b3545209a205ca1a54842be180eb63a16a6" dependencies = [ "cfg-if", "lazy_static", diff --git a/console-subscriber/Cargo.toml b/console-subscriber/Cargo.toml index 5c045870f..ecbc81ab4 100644 --- a/console-subscriber/Cargo.toml +++ b/console-subscriber/Cargo.toml @@ -30,6 +30,7 @@ parking_lot = ["parking_lot_crate", "tracing-subscriber/parking_lot"] [dependencies] +crossbeam-utils = "0.8.7" tokio = { version = "^1.15", features = ["sync", "time", "macros", "tracing"] } tokio-stream = "0.1" thread_local = "1.1.3" diff --git a/console-subscriber/src/stats.rs b/console-subscriber/src/stats.rs index ad2b67f67..b32d09a85 100644 --- a/console-subscriber/src/stats.rs +++ b/console-subscriber/src/stats.rs @@ -1,11 +1,12 @@ use crate::{attribute, sync::Mutex, ToProto}; +use crossbeam_utils::atomic::AtomicCell; use hdrhistogram::{ serialization::{Serializer, V2Serializer}, Histogram, }; use std::cmp; use std::sync::{ - atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering::*}, + atomic::{AtomicBool, AtomicUsize, Ordering::*}, Arc, }; use std::time::{Duration, SystemTime}; @@ -70,7 +71,7 @@ pub(crate) struct AsyncOpStats { /// /// This is set every time the async op is polled, in case a future is /// passed between tasks. - task_id: AtomicU64, + task_id: AtomicCell, /// Fields shared with `ResourceStats`. pub(crate) stats: ResourceStats, @@ -265,14 +266,14 @@ impl AsyncOpStats { parent_id: Option, ) -> Self { Self { - task_id: AtomicU64::new(0), + task_id: AtomicCell::new(0), stats: ResourceStats::new(created_at, inherit_child_attributes, parent_id), poll_stats: PollStats::default(), } } pub(crate) fn task_id(&self) -> Option { - let id = self.task_id.load(Acquire); + let id = self.task_id.load(); if id > 0 { Some(id as u64) } else { @@ -281,7 +282,7 @@ impl AsyncOpStats { } pub(crate) fn set_task_id(&self, id: &tracing::span::Id) { - self.task_id.store(id.into_u64(), Release); + self.task_id.store(id.into_u64()); self.make_dirty(); }