diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b1533d..a52b060 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.22.3] - unreleased + +### Added + +- Support all platforms with 32 bit atomics lacking 64 bit atomics. + See [PR 203]. + +[PR 203]: https://github.com/prometheus/client_rust/pull/203 + ## [0.22.2] ### Added diff --git a/src/metrics/counter.rs b/src/metrics/counter.rs index c1c5e51..63d84ff 100644 --- a/src/metrics/counter.rs +++ b/src/metrics/counter.rs @@ -6,7 +6,7 @@ use crate::encoding::{EncodeMetric, MetricEncoder}; use super::{MetricType, TypedMetric}; use std::marker::PhantomData; -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] use std::sync::atomic::AtomicU64; use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::Arc; @@ -40,7 +40,7 @@ use std::sync::Arc; /// counter.inc(); /// let _value: f64 = counter.get(); /// ``` -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] #[derive(Debug)] pub struct Counter { value: Arc, @@ -48,7 +48,7 @@ pub struct Counter { } /// Open Metrics [`Counter`] to measure discrete events. -#[cfg(any(target_arch = "mips", target_arch = "powerpc"))] +#[cfg(not(target_has_atomic = "64"))] #[derive(Debug)] pub struct Counter { value: Arc, @@ -114,7 +114,7 @@ pub trait Atomic { fn get(&self) -> N; } -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] impl Atomic for AtomicU64 { fn inc(&self) -> u64 { self.inc_by(1) @@ -143,7 +143,7 @@ impl Atomic for AtomicU32 { } } -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] impl Atomic for AtomicU64 { fn inc(&self) -> f64 { self.inc_by(1.0) @@ -231,7 +231,7 @@ mod tests { assert_eq!(1, counter.get()); } - #[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] + #[cfg(target_has_atomic = "64")] #[test] fn f64_stored_in_atomic_u64() { fn prop(fs: Vec) { diff --git a/src/metrics/exemplar.rs b/src/metrics/exemplar.rs index c8478c6..e61f4d5 100644 --- a/src/metrics/exemplar.rs +++ b/src/metrics/exemplar.rs @@ -11,9 +11,9 @@ use super::histogram::Histogram; use super::{MetricType, TypedMetric}; use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard}; use std::collections::HashMap; -#[cfg(any(target_arch = "mips", target_arch = "powerpc"))] +#[cfg(not(target_has_atomic = "64"))] use std::sync::atomic::AtomicU32; -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] use std::sync::atomic::AtomicU64; use std::sync::Arc; @@ -65,7 +65,7 @@ pub struct Exemplar { /// }), /// ); /// ``` -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] #[derive(Debug)] pub struct CounterWithExemplar { pub(crate) inner: Arc>>, @@ -77,7 +77,7 @@ impl TypedMetric for CounterWithExemplar { /// Open Metrics [`Counter`] with an [`Exemplar`] to both measure discrete /// events and track references to data outside of the metric set. -#[cfg(any(target_arch = "mips", target_arch = "powerpc"))] +#[cfg(not(target_has_atomic = "64"))] #[derive(Debug)] pub struct CounterWithExemplar { pub(crate) inner: Arc>>, diff --git a/src/metrics/gauge.rs b/src/metrics/gauge.rs index 7b26842..fcf7e6a 100644 --- a/src/metrics/gauge.rs +++ b/src/metrics/gauge.rs @@ -7,7 +7,7 @@ use crate::encoding::{EncodeGaugeValue, EncodeMetric, MetricEncoder}; use super::{MetricType, TypedMetric}; use std::marker::PhantomData; use std::sync::atomic::{AtomicI32, AtomicU32, Ordering}; -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] use std::sync::atomic::{AtomicI64, AtomicU64}; use std::sync::Arc; @@ -40,7 +40,7 @@ use std::sync::Arc; /// gauge.set(42.0); /// let _value: f64 = gauge.get(); /// ``` -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] #[derive(Debug)] pub struct Gauge { value: Arc, @@ -48,7 +48,7 @@ pub struct Gauge { } /// Open Metrics [`Gauge`] to record current measurements. -#[cfg(any(target_arch = "mips", target_arch = "powerpc"))] +#[cfg(not(target_has_atomic = "64"))] #[derive(Debug)] pub struct Gauge { value: Arc, @@ -186,7 +186,7 @@ impl Atomic for AtomicU32 { } } -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] impl Atomic for AtomicI64 { fn inc(&self) -> i64 { self.inc_by(1) @@ -213,7 +213,7 @@ impl Atomic for AtomicI64 { } } -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] impl Atomic for AtomicU64 { fn inc(&self) -> f64 { self.inc_by(1.0)