From 9d0f59652abd60356af1ad3b5302e7678d782848 Mon Sep 17 00:00:00 2001 From: llogiq Date: Fri, 25 Sep 2015 17:32:16 +0200 Subject: [PATCH 1/2] fixed overflow in bench_chan_latency --- src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 627cb7d..f2e4bfc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -848,7 +848,7 @@ mod test { } debug!("Exit write loop"); - if rx.recv().is_err() == true {panic!()} + assert!(!rx.recv().is_err()); debug!("Recv_opt done"); return; // @@ -1144,7 +1144,11 @@ mod test { counter += 1; let end = precise_time_ns(); let start = rx_bench.recv().ok().unwrap(); - let total = ((end - start) as i64).abs() as u64; // because ticks can go backwards between different cores + let total = if end > start { + end - start + } else { + start - end + }; // because ticks can go backwards between different cores latencies.push(total); //error!("{}, {}, {}", start, end, total); } From 76290e436735d449654cbb413885c496e0cd3359 Mon Sep 17 00:00:00 2001 From: llogiq Date: Fri, 25 Sep 2015 21:40:56 +0200 Subject: [PATCH 2/2] use wrapping operation --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index f2e4bfc..12bbdd8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -386,7 +386,7 @@ impl Turbine { //let diff = self.current_pos - v.load(); min_cursor = min(min_cursor, v.load()); - if self.current_pos - min_cursor >= self.size as u64 { + if self.current_pos.wrapping_sub(min_cursor) >= self.size as u64 { debug!("Not writeable! {} - {} == {}, which is >= {}", self.current_pos, min_cursor, (self.current_pos - min_cursor), self.size); return false; }