Skip to content

Commit cba62e9

Browse files
committed
Address comments, update Makefile and update ci
1 parent 752c9ac commit cba62e9

File tree

5 files changed

+21
-55
lines changed

5 files changed

+21
-55
lines changed

.travis.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ rust:
77
env:
88
- RUSTFLAGS=-Dwarnings
99

10+
script:
11+
- cargo test
12+
1013
matrix:
1114
include:
1215
- rust: nightly
13-
env:
14-
- FEATURE="--features dev"
1516
- RUSTFLAGS=-Dwarnings
16-
17-
script:
18-
- cargo test $FEATURE
17+
script:
18+
- cargo test --features dev
19+
- cargo test --features="dev nightly"

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test:
99
dev: format
1010
cargo build --features dev
1111
cargo test --features dev -- --nocapture
12+
cargo test --features="nightly dev" -- --nocapture
1213

1314
bench: format
1415
cargo bench --features dev -- --nocapture

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ mod registry;
4242
mod vec;
4343
mod histogram;
4444
mod push;
45-
#[cfg_attr(not(feature="nightly"), allow(dead_code))]
46-
mod util;
45+
#[cfg(feature="nightly")]
46+
mod atomicf64;
4747

4848
// Mods
4949

src/util.rs

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/value.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
#[cfg(not(feature = "nightly"))]
1616
use std::sync::RwLock;
1717
#[cfg(feature = "nightly")]
18-
use std::sync::atomic::{AtomicU64, Ordering};
18+
use std::sync::atomic::Ordering;
19+
#[cfg(feature = "nightly")]
20+
use std::f64::EPSILON;
1921

2022
use protobuf::RepeatedField;
2123

2224
use proto::{LabelPair, Metric, Counter, Gauge, Untyped, MetricFamily, MetricType};
2325
use desc::Desc;
2426
use errors::{Result, Error};
2527
#[cfg(feature = "nightly")]
26-
use util::{f64u64, u64f64};
28+
use atomicf64::AtomicF64;
2729

2830
/// `ValueType` is an enumeration of metric types that represent a simple value
2931
/// for `Counter`, `Gauge`, and `Untyped`.
@@ -57,7 +59,7 @@ pub struct Value {
5759
pub val: RwLock<f64>,
5860

5961
#[cfg(feature = "nightly")]
60-
pub val: AtomicU64,
62+
pub val: AtomicF64,
6163
}
6264

6365
#[cfg(not(feature = "nightly"))]
@@ -82,21 +84,21 @@ impl Value {
8284
impl Value {
8385
#[inline]
8486
pub fn set(&self, val: f64) {
85-
self.val.store(f64u64(val), Ordering::Release);
87+
self.val.store(val, Ordering::Release);
8688
}
8789

8890
#[inline]
8991
pub fn get(&self) -> f64 {
90-
u64f64(self.val.load(Ordering::Acquire))
92+
self.val.load(Ordering::Acquire)
9193
}
9294

9395
#[inline]
9496
pub fn inc_by(&self, delta: f64) {
9597
loop {
96-
let old = self.val.load(Ordering::Acquire);
97-
let new = f64u64(u64f64(old) + delta);
98-
let swapped = self.val.compare_and_swap(old, new, Ordering::Release);
99-
if swapped == old {
98+
let current = self.val.load(Ordering::Acquire);
99+
let new = current + delta;
100+
let swapped = self.val.compare_and_swap(current, new, Ordering::Release);
101+
if (swapped - current).abs() < EPSILON {
100102
return;
101103
}
102104
}
@@ -121,7 +123,7 @@ impl Value {
121123
_ => RwLock::new(val),
122124

123125
#[cfg(feature = "nightly")]
124-
_ => AtomicU64::new(f64u64(val)),
126+
_ => AtomicF64::new(val),
125127
};
126128

127129
Ok(Value {

0 commit comments

Comments
 (0)