Skip to content

Commit 2947bae

Browse files
committed
Use conditional Lock
1 parent dbd96d0 commit 2947bae

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

compiler/rustc_data_structures/src/sync/table/sync_table.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ use std::sync::Arc;
1616
use std::sync::atomic::{AtomicPtr, AtomicU8, AtomicUsize, Ordering};
1717
use std::{cmp, fmt, mem};
1818

19-
use parking_lot::{Mutex, MutexGuard};
19+
use parking_lot::Mutex;
2020

2121
use super::collect::{self, Pin, pin};
2222
use super::raw::bitmask::BitMask;
2323
use super::raw::imp::Group;
2424
use super::scopeguard::guard;
2525
use super::util::{cold_path, make_insert_hash};
26-
use crate::sync::{DynSend, DynSync};
26+
use crate::sync::{DynSend, DynSync, Lock, LockGuard};
2727

2828
mod code;
2929
mod tests;
@@ -137,7 +137,7 @@ pub struct Write<'a, K, V, S = DefaultHashBuilder> {
137137
/// A handle to a [SyncTable] with write access protected by a lock.
138138
pub struct LockedWrite<'a, K, V, S = DefaultHashBuilder> {
139139
table: Write<'a, K, V, S>,
140-
_guard: MutexGuard<'a, ()>,
140+
_guard: LockGuard<'a, ()>,
141141
}
142142

143143
impl<'a, K, V, S> Deref for LockedWrite<'a, K, V, S> {
@@ -167,7 +167,7 @@ pub struct SyncTable<K, V, S = DefaultHashBuilder> {
167167

168168
current: AtomicPtr<TableInfo>,
169169

170-
lock: Mutex<()>,
170+
lock: Lock<()>,
171171

172172
old: UnsafeCell<Vec<Arc<DestroyTable<(K, V)>>>>,
173173

@@ -702,7 +702,7 @@ impl<K, V, S> SyncTable<K, V, S> {
702702
),
703703
old: UnsafeCell::new(Vec::new()),
704704
marker: PhantomData,
705-
lock: Mutex::new(()),
705+
lock: Lock::new(()),
706706
}
707707
}
708708

@@ -714,7 +714,7 @@ impl<K, V, S> SyncTable<K, V, S> {
714714

715715
/// Gets a reference to the underlying mutex that protects writes.
716716
#[inline]
717-
pub fn mutex(&self) -> &Mutex<()> {
717+
pub fn mutex(&self) -> &Lock<()> {
718718
&self.lock
719719
}
720720

@@ -747,16 +747,16 @@ impl<K, V, S> SyncTable<K, V, S> {
747747
pub fn lock(&self) -> LockedWrite<'_, K, V, S> {
748748
LockedWrite { table: Write { table: self }, _guard: self.lock.lock() }
749749
}
750+
/*
751+
/// Creates a [LockedWrite] handle from a guard protecting the underlying mutex that protects writes.
752+
#[inline]
753+
pub fn lock_from_guard<'a>(&'a self, guard: LockGuard<'a, ()>) -> LockedWrite<'a, K, V, S> {
754+
// Verify that we are target of the guard
755+
assert_eq!(&self.lock as *const _, LockGuard::mutex(&guard) as *const _);
750756
751-
/// Creates a [LockedWrite] handle from a guard protecting the underlying mutex that protects writes.
752-
#[inline]
753-
pub fn lock_from_guard<'a>(&'a self, guard: MutexGuard<'a, ()>) -> LockedWrite<'a, K, V, S> {
754-
// Verify that we are target of the guard
755-
assert_eq!(&self.lock as *const _, MutexGuard::mutex(&guard) as *const _);
756-
757-
LockedWrite { table: Write { table: self }, _guard: guard }
758-
}
759-
757+
LockedWrite { table: Write { table: self }, _guard: guard }
758+
}
759+
*/
760760
#[inline]
761761
fn current(&self) -> TableRef<(K, V)> {
762762
TableRef {
@@ -928,7 +928,7 @@ impl<K: Hash + Clone, V: Clone, S: Clone + BuildHasher> Clone for SyncTable<K, V
928928
),
929929
old: UnsafeCell::new(Vec::new()),
930930
marker: PhantomData,
931-
lock: Mutex::new(()),
931+
lock: Lock::new(()),
932932
}
933933
}
934934
})

0 commit comments

Comments
 (0)