diff --git a/src/models/gates/mod.rs b/src/models/gates/mod.rs index 9a7ab11..85b69cf 100644 --- a/src/models/gates/mod.rs +++ b/src/models/gates/mod.rs @@ -26,8 +26,9 @@ macro_rules! create_simple_1i1o_gate { impl Updateable for $name { fn update(&mut self) -> bool { - let old_value = self.z.replace($func(self.a.value())); - old_value != *self.z.inner.value.read().unwrap() + let new_value = $func(self.a.value()); + let old_value = self.z.replace(new_value); + old_value != new_value } } @@ -59,8 +60,9 @@ macro_rules! create_simple_2i1o_gate { impl Updateable for $name { fn update(&mut self) -> bool { - let old_value = self.z.replace($func(self.a.value(), self.b.value())); - old_value != *self.z.inner.value.read().unwrap() + let new_value = $func(self.a.value(), self.b.value()); + let old_value = self.z.replace(new_value); + old_value != new_value } } diff --git a/src/models/gates/mux.rs b/src/models/gates/mux.rs index 929d9f8..ef76e0a 100644 --- a/src/models/gates/mux.rs +++ b/src/models/gates/mux.rs @@ -68,15 +68,17 @@ pub struct Mux { impl Updateable for Mux { fn update(&mut self) -> bool { - let old_value = self.z.replace(if self.s.value().is_1H() { + let new_value = if self.s.value().is_1H() { self.b.value() } else if self.s.value().is_0L() { self.a.value() } else { Ieee1164::_X - }); + }; - old_value != *self.z.inner.value.read().unwrap() + let old_value = self.z.replace(new_value); + + old_value != new_value } } diff --git a/src/models/gates/tri.rs b/src/models/gates/tri.rs index 408e9c2..165873e 100644 --- a/src/models/gates/tri.rs +++ b/src/models/gates/tri.rs @@ -20,15 +20,16 @@ pub struct TriBuffer { impl Updateable for TriBuffer { fn update(&mut self) -> bool { - let old_value = self.z.replace(if self.s.value().is_1H() { + let new_value = if self.s.value().is_1H() { self.a.value() } else if self.s.value().is_0L() { Ieee1164::_Z } else { Ieee1164::_X - }); + }; + let old_value = self.z.replace(new_value); - old_value != *self.z.inner.value.read().unwrap() + old_value != new_value } } diff --git a/src/models/rtlib/arithmic/add.rs b/src/models/rtlib/arithmic/add.rs index f294120..b2da060 100644 --- a/src/models/rtlib/arithmic/add.rs +++ b/src/models/rtlib/arithmic/add.rs @@ -1,6 +1,7 @@ use crate::direction::{Input, Output}; use crate::logicbit::mask_from_width; use crate::{Ieee1164, LogicVector, Port, Updateable}; +use crate::port::PortConnector; /// This models an actual adder that will add up both inputs. /// @@ -18,7 +19,7 @@ pub struct Add { impl Updateable for Add { fn update(&mut self) -> bool { - let old_value = self.s.inner.value.read().unwrap().clone(); + let old_value = PortConnector::from(self.s.clone()).value(); let a = self.a.value(); let b = self.b.value(); self.s.with_value_mut(|v| match (a.as_u128(), b.as_u128()) { @@ -28,6 +29,6 @@ impl Updateable for Add { _ => v.set_all_to(Ieee1164::_U), }); - old_value != *self.s.inner.value.read().unwrap() + old_value != PortConnector::from(self.s.clone()).value() } } diff --git a/src/models/rtlib/arithmic/twoscomplement.rs b/src/models/rtlib/arithmic/twoscomplement.rs index 0cde0a4..7ca51c4 100644 --- a/src/models/rtlib/arithmic/twoscomplement.rs +++ b/src/models/rtlib/arithmic/twoscomplement.rs @@ -1,6 +1,8 @@ use crate::direction::{Input, Output}; use crate::{LogicVector, Port, Updateable}; +use crate::port::PortConnector; + /// Computes the two's complement of the applied value. #[derive(Debug)] pub struct TwosComplement { @@ -12,9 +14,9 @@ pub struct TwosComplement { impl Updateable for TwosComplement { fn update(&mut self) -> bool { - let old_value = self.y.inner.value.read().unwrap().clone(); + let old_value = PortConnector::from(self.y.clone()).value(); let a = self.a.value(); self.y.with_value_mut(|y| *y = (!a).incr()); - old_value != *self.y.inner.value.read().unwrap() + old_value != PortConnector::from(self.y.clone()).value() } } diff --git a/src/models/rtlib/memory/rom.rs b/src/models/rtlib/memory/rom.rs index f291115..5c4d220 100644 --- a/src/models/rtlib/memory/rom.rs +++ b/src/models/rtlib/memory/rom.rs @@ -3,6 +3,7 @@ use std::iter::FromIterator; use crate::direction::{Input, Output}; use crate::{Ieee1164, LogicVector, Port, Updateable}; +use crate::port::PortConnector; /// This struct represents a Read-only-memory with a size of 1kB (1024 bytes). /// @@ -84,7 +85,7 @@ impl fmt::Debug for Rom1kx8 { impl Updateable for Rom1kx8 { fn update(&mut self) -> bool { println!("ROM Update"); - let old_value = self.data.inner.value.read().unwrap().clone(); + let old_value = PortConnector::from(self.data.clone()).value(); let ncs = self.n_chip_select.value(); let noe = self.n_output_enable.value(); let data = if let Some(addr) = self.addr.value().as_u128() { @@ -107,7 +108,7 @@ impl Updateable for Rom1kx8 { } }); - old_value != *self.data.inner.value.read().unwrap() + old_value != PortConnector::from(self.data.clone()).value() } } diff --git a/src/port/mod.rs b/src/port/mod.rs index b2c8b37..da59788 100644 --- a/src/port/mod.rs +++ b/src/port/mod.rs @@ -13,6 +13,6 @@ pub use self::pport::Port; #[derive(Debug)] pub(crate) struct InnerPort { - pub value: RwLock, + value: RwLock, signal: WeakSignal, }