Skip to content

Commit

Permalink
Avoid duplicated clocks in TimeSource
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Della Vedova <[email protected]>
  • Loading branch information
luca-della-vedova committed Aug 1, 2023
1 parent 213978f commit 1f5ea5c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions rclrs/src/time_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ impl TimeSource {
(last_msg.clock.sec as i64 * 1_000_000_000) + last_msg.clock.nanosec as i64;
Self::update_clock(&clock, nanoseconds);
}
// TODO(luca) this would allow duplicates to be stored in the vector but it seems other
// client libraries do the same, should we check and no-op if the value exists already?
self._clocks.lock().unwrap().push(clock);
let mut clocks = self._clocks.lock().unwrap();
if !clocks.iter().any(|c| Arc::ptr_eq(c, &clock)) {
clocks.push(clock);
}
Ok(())
}

Expand Down

0 comments on commit 1f5ea5c

Please sign in to comment.