aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Li <li.davidm96@gmail.com>2016-01-09 15:35:17 -0700
committerDavid Li <li.davidm96@gmail.com>2016-01-09 15:35:17 -0700
commitb85e63bc767bb382de64f54504151abbca6efeff (patch)
tree1dcee009d3f0641baf69c8f0c1b3b6a65db58242
parentad805c698cd1c4d68d090f842fb14621c32ee8d6 (diff)
Implement shareable cache
-rw-r--r--src/shareable_cache.rs15
1 files changed, 10 insertions, 5 deletions
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<RefCell<ShareableCache<'a>>>,
+ Rc<RefCell<ShareableCache<'a>>>) {
+ (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) {