Skip to content

Commit

Permalink
fix(subscriber): fix compilation on targets without 64-bit atomics (#282
Browse files Browse the repository at this point in the history
)

## Motivation

Currently, the `console-subscriber` crate does not compile on targets
without 64-bit atomic operations, such as `mipsel-unknown-linux-musl`.
This is because a 64-bit atomic is used to store the last task ID that
polled a resource.

## Solution

This branch changes this code to use the `AtomicCell` type from
`crossbeam-utils`, instead. `AtomicCell` will use atomic operations on
targets that support 64-bit atomics, and fall back to using a mutex on
platforms that don't have 64-bit atomic operations. This should fix the
build on those platforms.

Fixes #279
  • Loading branch information
hawkw authored Feb 14, 2022
1 parent fd309c0 commit 5590fdb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions console-subscriber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 6 additions & 5 deletions console-subscriber/src/stats.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<u64>,

/// Fields shared with `ResourceStats`.
pub(crate) stats: ResourceStats,
Expand Down Expand Up @@ -265,14 +266,14 @@ impl AsyncOpStats {
parent_id: Option<Id>,
) -> 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<u64> {
let id = self.task_id.load(Acquire);
let id = self.task_id.load();
if id > 0 {
Some(id as u64)
} else {
Expand All @@ -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();
}

Expand Down

0 comments on commit 5590fdb

Please sign in to comment.