Skip to content

Commit

Permalink
fix: check arch to use atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
TGLuong committed Nov 16, 2024
1 parent 2fe42eb commit c7d2896
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions opentelemetry-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ tokio = { workspace = true, features = ["rt", "time"], optional = true }
tokio-stream = { workspace = true, optional = true }
http = { workspace = true, optional = true }
tracing = {workspace = true, optional = true}

[target.'cfg(any(target_arch = "powerpc", target_arch = "mips"))'.dependencies]
portable-atomic = {workspace = true}

[package.metadata.docs.rs]
Expand Down
17 changes: 11 additions & 6 deletions opentelemetry-sdk/src/metrics/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ pub(crate) use aggregate::{AggregateBuilder, ComputeAggregation, Measure};
pub(crate) use exponential_histogram::{EXPO_MAX_SCALE, EXPO_MIN_SCALE};
use once_cell::sync::Lazy;
use opentelemetry::{otel_warn, KeyValue};

#[cfg(any(target_arch = "mips", target_arch = "powerpc"))]
use portable_atomic::{AtomicBool, AtomicI64, AtomicU64, AtomicUsize};

#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU64, AtomicUsize};

use crate::metrics::AttributeSet;

pub(crate) static STREAM_OVERFLOW_ATTRIBUTES: Lazy<Vec<KeyValue>> =
Expand Down Expand Up @@ -411,8 +416,8 @@ mod tests {
#[test]
fn can_add_and_get_u64_atomic_value() {
let atomic = u64::new_atomic_tracker(0);
atomic.add(15);
atomic.add(10);
AtomicTracker::add(&atomic, 15);
AtomicTracker::add(&atomic, 10);

let value = atomic.get_value();
assert_eq!(value, 25);
Expand All @@ -421,7 +426,7 @@ mod tests {
#[test]
fn can_reset_u64_atomic_value() {
let atomic = u64::new_atomic_tracker(0);
atomic.add(15);
AtomicTracker::add(&atomic, 15);

let value = atomic.get_and_reset_value();
let value2 = atomic.get_value();
Expand Down Expand Up @@ -450,8 +455,8 @@ mod tests {
#[test]
fn can_add_and_get_i64_atomic_value() {
let atomic = i64::new_atomic_tracker(0);
atomic.add(15);
atomic.add(-10);
AtomicTracker::add(&atomic, 15);
AtomicTracker::add(&atomic, -10);

let value = atomic.get_value();
assert_eq!(value, 5);
Expand All @@ -460,7 +465,7 @@ mod tests {
#[test]
fn can_reset_i64_atomic_value() {
let atomic = i64::new_atomic_tracker(0);
atomic.add(15);
AtomicTracker::add(&atomic, 15);

let value = atomic.get_and_reset_value();
let value2 = atomic.get_value();
Expand Down

0 comments on commit c7d2896

Please sign in to comment.