about summary refs log tree commit diff
path: root/src/libworkcache
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-03-24 18:11:51 -0700
committerbors <bors@rust-lang.org>2014-03-24 18:11:51 -0700
commit6bf3fca8ff90bbeff8d5c437aa784d0dbf8f9455 (patch)
tree7fe1f4e9c71ec942f54defdd4b1be123f212804f /src/libworkcache
parentbcaaffbe1e1c6a6a3abdabdb4fdaef36358dae33 (diff)
parent218461d01049242e3544337055b7f6d06943344b (diff)
downloadrust-6bf3fca8ff90bbeff8d5c437aa784d0dbf8f9455.tar.gz
rust-6bf3fca8ff90bbeff8d5c437aa784d0dbf8f9455.zip
auto merge of #12900 : alexcrichton/rust/rewrite-sync, r=brson
* Remove clone-ability from all primitives. All shared state will now come
  from the usage of the primitives being shared, not the primitives being
  inherently shareable. This allows for fewer allocations for stack-allocated
  primitives.
* Add `Mutex<T>` and `RWLock<T>` which are stack-allocated primitives for purely
  wrapping a piece of data
* Remove `RWArc<T>` in favor of `Arc<RWLock<T>>`
* Remove `MutexArc<T>` in favor of `Arc<Mutex<T>>`
* Shuffle around where things are located
  * The `arc` module now only contains `Arc`
  * A new `lock` module contains `Mutex`, `RWLock`, and `Barrier`
  * A new `raw` module contains the primitive implementations of `Semaphore`,
    `Mutex`, and `RWLock`
* The Deref/DerefMut trait was implemented where appropriate
* `CowArc` was removed, the functionality is now part of `Arc` and is tagged
  with `#[experimental]`.
* The crate now has #[deny(missing_doc)]
* `Arc` now supports weak pointers

This is not a large-scale rewrite of the functionality contained within the
`sync` crate, but rather a shuffling of who does what an a thinner hierarchy of
ownership to allow for better composability.
Diffstat (limited to 'src/libworkcache')
-rw-r--r--src/libworkcache/lib.rs32
1 files changed, 16 insertions, 16 deletions
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<Database>,
+    db: Arc<RWLock<Database>>,
     priv cfg: Arc<json::Object>,
     /// 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<T:Decodable<json::Decoder>>(s: &str) -> T {
 
 impl Context {
 
-    pub fn new(db: RWArc<Database>,
+    pub fn new(db: Arc<RWLock<Database>>,
                cfg: Arc<json::Object>) -> Context {
         Context::new_with_freshness(db, cfg, Arc::new(TreeMap::new()))
     }
 
-    pub fn new_with_freshness(db: RWArc<Database>,
+    pub fn new_with_freshness(db: Arc<RWLock<Database>>,
                               cfg: Arc<json::Object>,
                               freshness: Arc<FreshnessMap>) -> 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| {