From b85e63bc767bb382de64f54504151abbca6efeff Mon Sep 17 00:00:00 2001 From: David Li Date: Sat, 9 Jan 2016 15:35:17 -0700 Subject: Implement shareable cache --- src/shareable_cache.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/shareable_cache.rs b/src/shareable_cache.rs index b6c6654..a8fee51 100644 --- a/src/shareable_cache.rs +++ b/src/shareable_cache.rs @@ -1,9 +1,13 @@ +use std::cell::RefCell; +use std::rc::Rc; + use rustv::isa; use rustv::memory::{MemoryInterface, Result, SharedMemory}; /// A cache that can be used as two separate caches or one /// set-associative cache. -struct ShareableCache<'a> { +#[derive(Clone)] +pub struct ShareableCache<'a> { // The idea is to create two separate ShareableCaches, one for // each player. primary: SharedMemory<'a>, @@ -14,18 +18,19 @@ struct ShareableCache<'a> { impl<'a> ShareableCache<'a> { pub fn new(cache1: SharedMemory<'a>, cache2: SharedMemory<'a>) - -> (ShareableCache<'a>, ShareableCache<'a>) { - (ShareableCache { + -> (Rc>>, + Rc>>) { + (Rc::new(RefCell::new(ShareableCache { primary: cache1.clone(), secondary: cache2.clone(), secondary_enabled: false, use_secondary: false, - }, ShareableCache { + })), Rc::new(RefCell::new(ShareableCache { primary: cache2.clone(), secondary: cache1.clone(), secondary_enabled: false, use_secondary: false, - }) + }))) } pub fn enable_secondary(&mut self) { -- cgit v1.2.3