From 5163a26d30c1fcbdee939c93cc19a41cc5dbcaf8 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 22 Mar 2014 00:55:50 -0700 Subject: test: Update all tests with the sync changes --- src/libworkcache/lib.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/libworkcache') diff --git a/src/libworkcache/lib.rs b/src/libworkcache/lib.rs index 79ed15655cc..9c0328d4b11 100644 --- a/src/libworkcache/lib.rs +++ b/src/libworkcache/lib.rs @@ -26,7 +26,7 @@ extern crate sync; use serialize::json; use serialize::json::ToJson; use serialize::{Encoder, Encodable, Decoder, Decodable}; -use sync::{Arc,RWArc}; +use sync::{Arc, RWLock}; use collections::TreeMap; use std::str; use std::io; @@ -225,7 +225,7 @@ pub type FreshnessMap = TreeMap<~str,extern fn(&str,&str)->bool>; #[deriving(Clone)] pub struct Context { - db: RWArc, + db: Arc>, priv cfg: Arc, /// Map from kinds (source, exe, url, etc.) to a freshness function. /// The freshness function takes a name (e.g. file path) and value @@ -269,12 +269,12 @@ fn json_decode>(s: &str) -> T { impl Context { - pub fn new(db: RWArc, + pub fn new(db: Arc>, cfg: Arc) -> Context { Context::new_with_freshness(db, cfg, Arc::new(TreeMap::new())) } - pub fn new_with_freshness(db: RWArc, + pub fn new_with_freshness(db: Arc>, cfg: Arc, freshness: Arc) -> Context { Context { @@ -364,7 +364,7 @@ impl<'a> Prep<'a> { fn is_fresh(&self, cat: &str, kind: &str, name: &str, val: &str) -> bool { let k = kind.to_owned(); - let f = self.ctxt.freshness.get().find(&k); + let f = self.ctxt.freshness.deref().find(&k); debug!("freshness for: {}/{}/{}/{}", cat, kind, name, val) let fresh = match f { None => fail!("missing freshness-function for '{}'", kind), @@ -406,9 +406,10 @@ impl<'a> Prep<'a> { debug!("exec_work: looking up {} and {:?}", self.fn_name, self.declared_inputs); - let cached = self.ctxt.db.read(|db| { - db.prepare(self.fn_name, &self.declared_inputs) - }); + let cached = { + let db = self.ctxt.db.deref().read(); + db.deref().prepare(self.fn_name, &self.declared_inputs) + }; match cached { Some((ref disc_in, ref disc_out, ref res)) @@ -460,13 +461,12 @@ impl<'a, T:Send + WorkFromTask(prep, port) => { let (exe, v) = port.recv(); let s = json_encode(&v); - prep.ctxt.db.write(|db| { - db.cache(prep.fn_name, - &prep.declared_inputs, - &exe.discovered_inputs, - &exe.discovered_outputs, - s) - }); + let mut db = prep.ctxt.db.deref().write(); + db.deref_mut().cache(prep.fn_name, + &prep.declared_inputs, + &exe.discovered_inputs, + &exe.discovered_outputs, + s); v } } @@ -496,7 +496,7 @@ fn test() { let db_path = make_path(~"db.json"); - let cx = Context::new(RWArc::new(Database::new(db_path)), + let cx = Context::new(Arc::new(RWLock::new(Database::new(db_path))), Arc::new(TreeMap::new())); let s = cx.with_prep("test1", |prep| { -- cgit 1.4.1-3-g733a5