Skip to content

Commit 4b78df1

Browse files
navaatimxinden
andauthoredJul 2, 2024
chore(portability): support all platforms without 64 bit atomics (#203)
Notably, RISC-V 32 for ESP32-C3 chips. Signed-off-by: Léo Gillot-Lamure <leo.gillot@navaati.net> Signed-off-by: Max Inden <mail@max-inden.de> Co-authored-by: Max Inden <mail@max-inden.de>
1 parent bf196d7 commit 4b78df1

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed
 

‎CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.22.3] - unreleased
8+
9+
### Added
10+
11+
- Support all platforms with 32 bit atomics lacking 64 bit atomics.
12+
See [PR 203].
13+
14+
[PR 203]: https://github.com/prometheus/client_rust/pull/203
15+
716
## [0.22.2]
817

918
### Added

‎src/metrics/counter.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::encoding::{EncodeMetric, MetricEncoder};
66

77
use super::{MetricType, TypedMetric};
88
use std::marker::PhantomData;
9-
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
9+
#[cfg(target_has_atomic = "64")]
1010
use std::sync::atomic::AtomicU64;
1111
use std::sync::atomic::{AtomicU32, Ordering};
1212
use std::sync::Arc;
@@ -40,15 +40,15 @@ use std::sync::Arc;
4040
/// counter.inc();
4141
/// let _value: f64 = counter.get();
4242
/// ```
43-
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
43+
#[cfg(target_has_atomic = "64")]
4444
#[derive(Debug)]
4545
pub struct Counter<N = u64, A = AtomicU64> {
4646
value: Arc<A>,
4747
phantom: PhantomData<N>,
4848
}
4949

5050
/// Open Metrics [`Counter`] to measure discrete events.
51-
#[cfg(any(target_arch = "mips", target_arch = "powerpc"))]
51+
#[cfg(not(target_has_atomic = "64"))]
5252
#[derive(Debug)]
5353
pub struct Counter<N = u32, A = AtomicU32> {
5454
value: Arc<A>,
@@ -114,7 +114,7 @@ pub trait Atomic<N> {
114114
fn get(&self) -> N;
115115
}
116116

117-
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
117+
#[cfg(target_has_atomic = "64")]
118118
impl Atomic<u64> for AtomicU64 {
119119
fn inc(&self) -> u64 {
120120
self.inc_by(1)
@@ -143,7 +143,7 @@ impl Atomic<u32> for AtomicU32 {
143143
}
144144
}
145145

146-
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
146+
#[cfg(target_has_atomic = "64")]
147147
impl Atomic<f64> for AtomicU64 {
148148
fn inc(&self) -> f64 {
149149
self.inc_by(1.0)
@@ -231,7 +231,7 @@ mod tests {
231231
assert_eq!(1, counter.get());
232232
}
233233

234-
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
234+
#[cfg(target_has_atomic = "64")]
235235
#[test]
236236
fn f64_stored_in_atomic_u64() {
237237
fn prop(fs: Vec<f64>) {

‎src/metrics/exemplar.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use super::histogram::Histogram;
1111
use super::{MetricType, TypedMetric};
1212
use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard};
1313
use std::collections::HashMap;
14-
#[cfg(any(target_arch = "mips", target_arch = "powerpc"))]
14+
#[cfg(not(target_has_atomic = "64"))]
1515
use std::sync::atomic::AtomicU32;
16-
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
16+
#[cfg(target_has_atomic = "64")]
1717
use std::sync::atomic::AtomicU64;
1818
use std::sync::Arc;
1919

@@ -65,7 +65,7 @@ pub struct Exemplar<S, V> {
6565
/// }),
6666
/// );
6767
/// ```
68-
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
68+
#[cfg(target_has_atomic = "64")]
6969
#[derive(Debug)]
7070
pub struct CounterWithExemplar<S, N = u64, A = AtomicU64> {
7171
pub(crate) inner: Arc<RwLock<CounterWithExemplarInner<S, N, A>>>,
@@ -77,7 +77,7 @@ impl<S> TypedMetric for CounterWithExemplar<S> {
7777

7878
/// Open Metrics [`Counter`] with an [`Exemplar`] to both measure discrete
7979
/// events and track references to data outside of the metric set.
80-
#[cfg(any(target_arch = "mips", target_arch = "powerpc"))]
80+
#[cfg(not(target_has_atomic = "64"))]
8181
#[derive(Debug)]
8282
pub struct CounterWithExemplar<S, N = u32, A = AtomicU32> {
8383
pub(crate) inner: Arc<RwLock<CounterWithExemplarInner<S, N, A>>>,

‎src/metrics/gauge.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::encoding::{EncodeGaugeValue, EncodeMetric, MetricEncoder};
77
use super::{MetricType, TypedMetric};
88
use std::marker::PhantomData;
99
use std::sync::atomic::{AtomicI32, AtomicU32, Ordering};
10-
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
10+
#[cfg(target_has_atomic = "64")]
1111
use std::sync::atomic::{AtomicI64, AtomicU64};
1212
use std::sync::Arc;
1313

@@ -40,15 +40,15 @@ use std::sync::Arc;
4040
/// gauge.set(42.0);
4141
/// let _value: f64 = gauge.get();
4242
/// ```
43-
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
43+
#[cfg(target_has_atomic = "64")]
4444
#[derive(Debug)]
4545
pub struct Gauge<N = i64, A = AtomicI64> {
4646
value: Arc<A>,
4747
phantom: PhantomData<N>,
4848
}
4949

5050
/// Open Metrics [`Gauge`] to record current measurements.
51-
#[cfg(any(target_arch = "mips", target_arch = "powerpc"))]
51+
#[cfg(not(target_has_atomic = "64"))]
5252
#[derive(Debug)]
5353
pub struct Gauge<N = i32, A = AtomicI32> {
5454
value: Arc<A>,
@@ -186,7 +186,7 @@ impl Atomic<u32> for AtomicU32 {
186186
}
187187
}
188188

189-
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
189+
#[cfg(target_has_atomic = "64")]
190190
impl Atomic<i64> for AtomicI64 {
191191
fn inc(&self) -> i64 {
192192
self.inc_by(1)
@@ -213,7 +213,7 @@ impl Atomic<i64> for AtomicI64 {
213213
}
214214
}
215215

216-
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
216+
#[cfg(target_has_atomic = "64")]
217217
impl Atomic<f64> for AtomicU64 {
218218
fn inc(&self) -> f64 {
219219
self.inc_by(1.0)

0 commit comments

Comments
 (0)
Please sign in to comment.