From b5c339a402a0afca1fe8f3b73c04b4462c9b7b26 Mon Sep 17 00:00:00 2001 From: Teodor Wozniak Date: Sat, 31 Aug 2024 01:57:26 +0200 Subject: [PATCH] simplified cloning --- statime-linux/src/main.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/statime-linux/src/main.rs b/statime-linux/src/main.rs index e15beedc8..2cf4694e7 100644 --- a/statime-linux/src/main.rs +++ b/statime-linux/src/main.rs @@ -37,10 +37,20 @@ use tokio::{ time::Sleep, }; -trait PortClock: Clock::Error> + PortTimestampToTime {} -impl PortClock for LinuxClock {} -impl PortClock for SharedClock> {} -type BoxedClock = Box; +trait PortClock: Clock::Error> + PortTimestampToTime + Send + Sync { + fn clone_box(&self) -> Box; +} +impl PortClock for LinuxClock { + fn clone_box(&self) -> Box { + Box::new(self.clone()) + } +} +impl PortClock for SharedClock> { + fn clone_box(&self) -> Box { + Box::new(self.clone()) + } +} +type BoxedClock = Box; type SharedOverlayClock = SharedClock>; #[derive(Parser, Debug)] @@ -302,7 +312,7 @@ async fn actual_main() { for port_config in config.ports { let interface = port_config.interface; let network_mode = port_config.network_mode; - let (port_clock, port_clock2, timestamping) = match port_config.hardware_clock { + let (port_clock, timestamping) = match port_config.hardware_clock { Some(idx) => { let clock = LinuxClock::open_idx(idx).expect("Unable to open clock"); if let Some(id) = clock_name_map.get(&idx) { @@ -315,7 +325,6 @@ async fn actual_main() { .push(start_clock_task(clock.clone(), system_clock.clone())); } ( - Box::new(clock.clone()) as BoxedClock, Box::new(clock) as BoxedClock, InterfaceTimestampMode::HardwarePTPAll, ) @@ -323,7 +332,6 @@ async fn actual_main() { None => { clock_port_map.push(None); ( - system_clock.clone_boxed(), system_clock.clone_boxed(), InterfaceTimestampMode::SoftwareAll, ) @@ -335,7 +343,7 @@ async fn actual_main() { let port = instance.add_port( port_config.into(), KalmanConfiguration::default(), - port_clock2, + port_clock.clone_box(), rng, );