From 51963990636f8ddb2fe0ae607a67c96dff62195e Mon Sep 17 00:00:00 2001 From: Thoren Paulson <3453006+thoren-d@users.noreply.github.com> Date: Fri, 15 Mar 2024 14:20:01 -0700 Subject: [PATCH] Replace use of AtomicU64 with AtomicUsize. (#28) This should be sufficient as std requires pointer-sized atomic support. Fixes #27 (cherry picked from commit 7e2625ab4aeeef2f0ef9bde9d6258dd181c04472) --- Cargo.toml | 12 ++++++------ src/lib.rs | 25 +++++++++++++------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 34f4008..55b5445 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,15 +15,15 @@ repository = "https://github.com/thoren-d/tracing-chrome" exclude = ["/doc"] [dependencies] -serde_json = "1.0.93" -tracing-core = "0.1.30" -tracing-subscriber = "0.3.16" +serde_json = "1.0.114" +tracing-core = "0.1.32" +tracing-subscriber = "0.3.18" [dev-dependencies] -criterion = "0.4.0" -rayon = "1.6.1" -tracing = "0.1.37" +criterion = "0.5.1" +rayon = "1.9.0" +tracing = "0.1.40" [[bench]] diff --git a/src/lib.rs b/src/lib.rs index 2a5b47e..e46a55d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,7 @@ use std::{ marker::PhantomData, path::Path, sync::{ - atomic::{AtomicU64, Ordering}, + atomic::{AtomicUsize, Ordering}, Arc, Mutex, }, }; @@ -26,8 +26,8 @@ use std::{ }; thread_local! { - static OUT: RefCell>> = RefCell::new(None); - static TID: RefCell> = RefCell::new(None); + static OUT: RefCell>> = const { RefCell::new(None) }; + static TID: RefCell> = const { RefCell::new(None) }; } type NameFn = Box) -> String + Send + Sync>; @@ -40,7 +40,7 @@ where { out: Arc>>, start: std::time::Instant, - max_tid: AtomicU64, + max_tid: AtomicUsize, include_args: bool, include_locations: bool, trace_style: TraceStyle, @@ -88,7 +88,7 @@ where include_args: false, include_locations: true, trace_style: TraceStyle::Threaded, - _inner: PhantomData::default(), + _inner: PhantomData, } } @@ -240,7 +240,7 @@ impl Drop for FlushGuard { } struct Callsite { - tid: u64, + tid: usize, name: String, target: String, file: Option<&'static str>, @@ -252,7 +252,7 @@ enum Message { Enter(f64, Callsite, Option), Event(f64, Callsite), Exit(f64, Callsite, Option), - NewThread(u64, String), + NewThread(usize, String), Flush, Drop, StartNew(Option>), @@ -297,7 +297,7 @@ where write.write_all(b"[\n").unwrap(); let mut has_started = false; - let mut thread_names: Vec<(u64, String)> = Vec::new(); + let mut thread_names: Vec<(usize, String)> = Vec::new(); for msg in rx { if let Message::Flush = &msg { write.flush().unwrap(); @@ -407,19 +407,19 @@ where let layer = ChromeLayer { out: Arc::new(Mutex::new(tx)), start: std::time::Instant::now(), - max_tid: AtomicU64::new(0), + max_tid: AtomicUsize::new(0), name_fn: builder.name_fn.take(), cat_fn: builder.cat_fn.take(), include_args: builder.include_args, include_locations: builder.include_locations, trace_style: builder.trace_style, - _inner: PhantomData::default(), + _inner: PhantomData, }; (layer, guard) } - fn get_tid(&self) -> (u64, bool) { + fn get_tid(&self) -> (usize, bool) { TID.with(|value| { let tid = *value.borrow(); match tid { @@ -454,7 +454,8 @@ where EventOrSpan::Span(s) => s .extensions() .get::() - .map(|e| Arc::clone(&e.args)), + .map(|e| &e.args) + .cloned(), }; let name = name.unwrap_or_else(|| meta.name().into()); let target = target.unwrap_or_else(|| meta.target().into());