]> git.lizzy.rs Git - rust.git/commitdiff
Make CStore thread-safe
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Thu, 15 Feb 2018 09:52:26 +0000 (10:52 +0100)
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Mon, 12 Mar 2018 16:01:35 +0000 (17:01 +0100)
src/librustc_metadata/cstore.rs

index 19f43c180de3804f481a4180ed347c201d856aab..bd5ad93946e3cf9a10f9531fb423af50942cbc4a 100644 (file)
@@ -89,21 +89,23 @@ pub struct CrateMetadata {
 }
 
 pub struct CStore {
-    metas: RefCell<IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>>,
+    metas: RwLock<IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>>,
     /// Map from NodeId's of local extern crate statements to crate numbers
-    extern_mod_crate_map: RefCell<NodeMap<CrateNum>>,
+    extern_mod_crate_map: Lock<NodeMap<CrateNum>>,
     pub metadata_loader: Box<MetadataLoader + Sync>,
 }
 
 impl CStore {
     pub fn new(metadata_loader: Box<MetadataLoader + Sync>) -> CStore {
         CStore {
-            metas: RefCell::new(IndexVec::new()),
-            extern_mod_crate_map: RefCell::new(FxHashMap()),
+            metas: RwLock::new(IndexVec::new()),
+            extern_mod_crate_map: Lock::new(FxHashMap()),
             metadata_loader,
         }
     }
 
+    /// You cannot use this function to allocate a CrateNum in a thread-safe manner.
+    /// It is currently only used in CrateLoader which is single-threaded code.
     pub fn next_crate_num(&self) -> CrateNum {
         CrateNum::new(self.metas.borrow().len() + 1)
     }