-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
whitequark
committed
Oct 1, 2016
1 parent
d825393
commit 8bced9d
Showing
5 changed files
with
100 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::vec::Vec; | ||
use std::string::String; | ||
use std::btree_map::BTreeMap; | ||
|
||
#[derive(Debug)] | ||
struct Entry { | ||
data: Vec<u32>, | ||
borrowed: bool | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct Cache { | ||
entries: BTreeMap<String, Entry> | ||
} | ||
|
||
impl Cache { | ||
pub fn new() -> Cache { | ||
Cache { entries: BTreeMap::new() } | ||
} | ||
|
||
pub fn get(&mut self, key: &str) -> *const [u32] { | ||
match self.entries.get_mut(key) { | ||
None => &[], | ||
Some(ref mut entry) => { | ||
entry.borrowed = true; | ||
&entry.data[..] | ||
} | ||
} | ||
} | ||
|
||
pub fn put(&mut self, key: &str, data: &[u32]) -> Result<(), ()> { | ||
match self.entries.get_mut(key) { | ||
None => (), | ||
Some(ref mut entry) => { | ||
if entry.borrowed { return Err(()) } | ||
entry.data = Vec::from(data); | ||
return Ok(()) | ||
} | ||
} | ||
|
||
self.entries.insert(String::from(key), Entry { | ||
data: Vec::from(data), | ||
borrowed: false | ||
}); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,6 +249,7 @@ mod c { | |
|
||
#[repr(u32)] | ||
#[derive(Debug)] | ||
#[allow(dead_code)] | ||
pub enum Type { | ||
LoadRequest, | ||
LoadReply, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ mod rtio_crg; | |
mod mailbox; | ||
|
||
mod logger; | ||
mod cache; | ||
|
||
mod kernel_proto; | ||
mod session_proto; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#![allow(dead_code)] | ||
|
||
extern crate fringe; | ||
extern crate lwip; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters