about summary refs log tree commit diff
path: root/src/librustc_data_structures
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-06-19 06:51:18 +0000
committerbors <bors@rust-lang.org>2018-06-19 06:51:18 +0000
commit1cfb628eade1fc41d2dc57aafe5ca637c777f3c2 (patch)
treee097eb4c9992dc64a71097f4a331e3f5279403a1 /src/librustc_data_structures
parented39523406fea9d4c82f87f4ac9ad92388084123 (diff)
parentfe1cb88c08737a73e98f94d077bb23064de18106 (diff)
downloadrust-1cfb628eade1fc41d2dc57aafe5ca637c777f3c2.tar.gz
rust-1cfb628eade1fc41d2dc57aafe5ca637c777f3c2.zip
Auto merge of #51383 - Zoxc:parallel-stuff, r=nikomatsakis
Run some stuff in parallel

Requires https://github.com/rust-lang/rust/pull/50699 to actually work correctly.

r? @nikomatsakis
Diffstat (limited to 'src/librustc_data_structures')
-rw-r--r--src/librustc_data_structures/sync.rs45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/librustc_data_structures/sync.rs b/src/librustc_data_structures/sync.rs
index 33f6eda2a87..b82fe3ec60c 100644
--- a/src/librustc_data_structures/sync.rs
+++ b/src/librustc_data_structures/sync.rs
@@ -26,6 +26,8 @@
 //!
 //! `MTLock` is a mutex which disappears if cfg!(parallel_queries) is false.
 //!
+//! `MTRef` is a immutable refernce if cfg!(parallel_queries), and an mutable reference otherwise.
+//!
 //! `rustc_erase_owner!` erases a OwningRef owner into Erased or Erased + Send + Sync
 //! depending on the value of cfg!(parallel_queries).
 
@@ -126,6 +128,8 @@ cfg_if! {
             }
         }
 
+        pub type MTRef<'a, T> = &'a mut T;
+
         #[derive(Debug)]
         pub struct MTLock<T>(T);
 
@@ -151,13 +155,8 @@ cfg_if! {
             }
 
             #[inline(always)]
-            pub fn borrow(&self) -> &T {
-                &self.0
-            }
-
-            #[inline(always)]
-            pub fn borrow_mut(&self) -> &T {
-                &self.0
+            pub fn lock_mut(&mut self) -> &mut T {
+                &mut self.0
             }
         }
 
@@ -221,7 +220,37 @@ cfg_if! {
         pub use std::sync::Arc as Lrc;
         pub use std::sync::Weak as Weak;
 
-        pub use self::Lock as MTLock;
+        pub type MTRef<'a, T> = &'a T;
+
+        #[derive(Debug)]
+        pub struct MTLock<T>(Lock<T>);
+
+        impl<T> MTLock<T> {
+            #[inline(always)]
+            pub fn new(inner: T) -> Self {
+                MTLock(Lock::new(inner))
+            }
+
+            #[inline(always)]
+            pub fn into_inner(self) -> T {
+                self.0.into_inner()
+            }
+
+            #[inline(always)]
+            pub fn get_mut(&mut self) -> &mut T {
+                self.0.get_mut()
+            }
+
+            #[inline(always)]
+            pub fn lock(&self) -> LockGuard<T> {
+                self.0.lock()
+            }
+
+            #[inline(always)]
+            pub fn lock_mut(&self) -> LockGuard<T> {
+                self.lock()
+            }
+        }
 
         use parking_lot::Mutex as InnerLock;
         use parking_lot::RwLock as InnerRwLock;