Skip to content

Commit 1f5ea5c

Browse files
Avoid duplicated clocks in TimeSource
Signed-off-by: Luca Della Vedova <[email protected]>
1 parent 213978f commit 1f5ea5c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

rclrs/src/time_source.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,10 @@ impl TimeSource {
117117
(last_msg.clock.sec as i64 * 1_000_000_000) + last_msg.clock.nanosec as i64;
118118
Self::update_clock(&clock, nanoseconds);
119119
}
120-
// TODO(luca) this would allow duplicates to be stored in the vector but it seems other
121-
// client libraries do the same, should we check and no-op if the value exists already?
122-
self._clocks.lock().unwrap().push(clock);
120+
let mut clocks = self._clocks.lock().unwrap();
121+
if !clocks.iter().any(|c| Arc::ptr_eq(c, &clock)) {
122+
clocks.push(clock);
123+
}
123124
Ok(())
124125
}
125126

0 commit comments

Comments
 (0)