aboutsummaryrefslogtreecommitdiff
path: root/src/shareable_cache.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/shareable_cache.rs')
-rw-r--r--src/shareable_cache.rs26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/shareable_cache.rs b/src/shareable_cache.rs
index a8fee51..09d514f 100644
--- a/src/shareable_cache.rs
+++ b/src/shareable_cache.rs
@@ -1,6 +1,3 @@
-use std::cell::RefCell;
-use std::rc::Rc;
-
use rustv::isa;
use rustv::memory::{MemoryInterface, Result, SharedMemory};
@@ -8,8 +5,6 @@ use rustv::memory::{MemoryInterface, Result, SharedMemory};
/// set-associative cache.
#[derive(Clone)]
pub struct ShareableCache<'a> {
- // The idea is to create two separate ShareableCaches, one for
- // each player.
primary: SharedMemory<'a>,
secondary: SharedMemory<'a>,
secondary_enabled: bool,
@@ -18,19 +13,19 @@ pub struct ShareableCache<'a> {
impl<'a> ShareableCache<'a> {
pub fn new(cache1: SharedMemory<'a>, cache2: SharedMemory<'a>)
- -> (Rc<RefCell<ShareableCache<'a>>>,
- Rc<RefCell<ShareableCache<'a>>>) {
- (Rc::new(RefCell::new(ShareableCache {
+ -> (ShareableCache<'a>,
+ ShareableCache<'a>) {
+ (ShareableCache {
primary: cache1.clone(),
secondary: cache2.clone(),
secondary_enabled: false,
use_secondary: false,
- })), Rc::new(RefCell::new(ShareableCache {
+ }, ShareableCache {
primary: cache2.clone(),
secondary: cache1.clone(),
secondary_enabled: false,
use_secondary: false,
- })))
+ })
}
pub fn enable_secondary(&mut self) {
@@ -86,10 +81,17 @@ impl<'a> MemoryInterface for ShareableCache<'a> {
fn write_word(&mut self, address: isa::Address, value: isa::Word) -> Result<()> {
if self.secondary_enabled {
- if self.primary.borrow().is_address_accessible(address) {
+ let primary_accessible = {
+ self.primary.borrow().is_address_accessible(address)
+ };
+ let secondary_accessible = {
+ self.secondary.borrow().is_address_accessible(address)
+ };
+
+ if primary_accessible {
self.primary.borrow_mut().write_word(address, value)
}
- else if self.secondary.borrow().is_address_accessible(address) {
+ else if secondary_accessible {
self.secondary.borrow_mut().write_word(address, value)
}
else {