Skip to content

Commit

Permalink
feat: use portable-atomic to enable using opentelemetry-sdk for xtens…
Browse files Browse the repository at this point in the history
…a arch
  • Loading branch information
brunobrolesi committed Mar 9, 2025
1 parent 2fca21c commit d6894e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
3 changes: 3 additions & 0 deletions opentelemetry-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ tokio-stream = { workspace = true, optional = true }
http = { workspace = true, optional = true }
tracing = {workspace = true, optional = true}

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

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
Expand Down
27 changes: 17 additions & 10 deletions opentelemetry-sdk/src/metrics/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ use core::fmt;
use std::collections::{HashMap, HashSet};
use std::mem::swap;
use std::ops::{Add, AddAssign, DerefMut, Sub};
use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU64, AtomicUsize, Ordering};
use std::sync::atomic::{Ordering};

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

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

use std::sync::{Arc, OnceLock, RwLock};

use aggregate::{is_under_cardinality_limit, STREAM_CARDINALITY_LIMIT};
Expand Down Expand Up @@ -439,8 +446,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 @@ -449,7 +456,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 @@ -478,8 +485,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 @@ -488,7 +495,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 Expand Up @@ -517,8 +524,8 @@ mod tests {
#[test]
fn can_add_and_get_f64_atomic_value() {
let atomic = f64::new_atomic_tracker(0.0);
atomic.add(15.3);
atomic.add(10.4);
AtomicTracker::add(&atomic,15.3);
AtomicTracker::add(&atomic,10.4);

let value = atomic.get_value();

Expand All @@ -528,7 +535,7 @@ mod tests {
#[test]
fn can_reset_f64_atomic_value() {
let atomic = f64::new_atomic_tracker(0.0);
atomic.add(15.5);
AtomicTracker::add(&atomic,15.5);

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

0 comments on commit d6894e4

Please sign in to comment.