summaryrefslogtreecommitdiffstats
path: root/vendor/lock_api
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/lock_api
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/lock_api')
-rw-r--r--vendor/lock_api/.cargo-checksum.json2
-rw-r--r--vendor/lock_api/Cargo.toml4
-rw-r--r--vendor/lock_api/src/mutex.rs34
-rw-r--r--vendor/lock_api/src/remutex.rs36
-rw-r--r--vendor/lock_api/src/rwlock.rs128
5 files changed, 132 insertions, 72 deletions
diff --git a/vendor/lock_api/.cargo-checksum.json b/vendor/lock_api/.cargo-checksum.json
index b4297e76f..f525b6ddf 100644
--- a/vendor/lock_api/.cargo-checksum.json
+++ b/vendor/lock_api/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.toml":"12fd624e0a205bf395226b5ce7339f7d7060cd8be40c7603e517e0f0ff1ded84","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"c9a75f18b9ab2927829a208fc6aa2cf4e63b8420887ba29cdb265d6619ae82d5","build.rs":"af84139c71d151adead0b4398c394a7dd16087bb2db44b14a0ed970ce868a6c6","src/lib.rs":"4d2f97a740d3bda0cf2ba0ccbaa44a294952a701fc5a8219a755b4187bab29d4","src/mutex.rs":"eb6b92e848c3736fa463bec45eb7a8f2738cad2d4b36b3931ca30b1e70ab46c9","src/remutex.rs":"cf4d2fe406cd663155f39e6b85cb41e9e5c497f4e39c868a0d00675be5dc1115","src/rwlock.rs":"ce0ff32edc011ddfac22598acb12f6615ffa6d4609ed8d1b33e59caeb403c554"},"package":"c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16"} \ No newline at end of file
+{"files":{"Cargo.toml":"33d5077741ae3052ec99816d7390a65220b898b87fb100589d5783352d4052f5","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"c9a75f18b9ab2927829a208fc6aa2cf4e63b8420887ba29cdb265d6619ae82d5","build.rs":"af84139c71d151adead0b4398c394a7dd16087bb2db44b14a0ed970ce868a6c6","src/lib.rs":"4d2f97a740d3bda0cf2ba0ccbaa44a294952a701fc5a8219a755b4187bab29d4","src/mutex.rs":"d24c765e7b371542992465027dba520e66a09e67a78324ab8396449aadad0d77","src/remutex.rs":"036fb60892d4b727257dbdf68a921738f048a94ed5ca0a1bb78ee0f68381cf9e","src/rwlock.rs":"4b85d7b42474ebe0ba91f6fd953232510164989ce5ef1511790de486d8960301"},"package":"3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"} \ No newline at end of file
diff --git a/vendor/lock_api/Cargo.toml b/vendor/lock_api/Cargo.toml
index 7a3f3a8ad..501db6e3c 100644
--- a/vendor/lock_api/Cargo.toml
+++ b/vendor/lock_api/Cargo.toml
@@ -11,8 +11,9 @@
[package]
edition = "2018"
+rust-version = "1.49.0"
name = "lock_api"
-version = "0.4.10"
+version = "0.4.11"
authors = ["Amanieu d'Antras <amanieu@gmail.com>"]
description = "Wrappers to create fully-featured Mutex and RwLock types. Compatible with no_std."
keywords = [
@@ -33,6 +34,7 @@ all-features = true
rustdoc-args = [
"--cfg",
"docsrs",
+ "--generate-link-to-definition",
]
[dependencies.owning_ref]
diff --git a/vendor/lock_api/src/mutex.rs b/vendor/lock_api/src/mutex.rs
index 29533c9a5..80eadfa9f 100644
--- a/vendor/lock_api/src/mutex.rs
+++ b/vendor/lock_api/src/mutex.rs
@@ -189,11 +189,16 @@ impl<R, T> Mutex<R, T> {
}
impl<R: RawMutex, T: ?Sized> Mutex<R, T> {
+ /// Creates a new `MutexGuard` without checking if the mutex is locked.
+ ///
/// # Safety
///
- /// The lock must be held when calling this method.
+ /// This method must only be called if the thread logically holds the lock.
+ ///
+ /// Calling this function when a guard has already been produced is undefined behaviour unless
+ /// the guard was forgotten with `mem::forget`.
#[inline]
- unsafe fn guard(&self) -> MutexGuard<'_, R, T> {
+ pub unsafe fn make_guard_unchecked(&self) -> MutexGuard<'_, R, T> {
MutexGuard {
mutex: self,
marker: PhantomData,
@@ -213,7 +218,7 @@ impl<R: RawMutex, T: ?Sized> Mutex<R, T> {
pub fn lock(&self) -> MutexGuard<'_, R, T> {
self.raw.lock();
// SAFETY: The lock is held, as required.
- unsafe { self.guard() }
+ unsafe { self.make_guard_unchecked() }
}
/// Attempts to acquire this lock.
@@ -227,7 +232,7 @@ impl<R: RawMutex, T: ?Sized> Mutex<R, T> {
pub fn try_lock(&self) -> Option<MutexGuard<'_, R, T>> {
if self.raw.try_lock() {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.guard() })
+ Some(unsafe { self.make_guard_unchecked() })
} else {
None
}
@@ -294,12 +299,17 @@ impl<R: RawMutex, T: ?Sized> Mutex<R, T> {
self.data.get()
}
+ /// Creates a new `ArcMutexGuard` without checking if the mutex is locked.
+ ///
/// # Safety
///
- /// The lock needs to be held for the behavior of this function to be defined.
+ /// This method must only be called if the thread logically holds the lock.
+ ///
+ /// Calling this function when a guard has already been produced is undefined behaviour unless
+ /// the guard was forgotten with `mem::forget`.
#[cfg(feature = "arc_lock")]
#[inline]
- unsafe fn guard_arc(self: &Arc<Self>) -> ArcMutexGuard<R, T> {
+ unsafe fn make_arc_guard_unchecked(self: &Arc<Self>) -> ArcMutexGuard<R, T> {
ArcMutexGuard {
mutex: self.clone(),
marker: PhantomData,
@@ -315,7 +325,7 @@ impl<R: RawMutex, T: ?Sized> Mutex<R, T> {
pub fn lock_arc(self: &Arc<Self>) -> ArcMutexGuard<R, T> {
self.raw.lock();
// SAFETY: the locking guarantee is upheld
- unsafe { self.guard_arc() }
+ unsafe { self.make_arc_guard_unchecked() }
}
/// Attempts to acquire a lock through an `Arc`.
@@ -327,7 +337,7 @@ impl<R: RawMutex, T: ?Sized> Mutex<R, T> {
pub fn try_lock_arc(self: &Arc<Self>) -> Option<ArcMutexGuard<R, T>> {
if self.raw.try_lock() {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.guard_arc() })
+ Some(unsafe { self.make_arc_guard_unchecked() })
} else {
None
}
@@ -362,7 +372,7 @@ impl<R: RawMutexTimed, T: ?Sized> Mutex<R, T> {
pub fn try_lock_for(&self, timeout: R::Duration) -> Option<MutexGuard<'_, R, T>> {
if self.raw.try_lock_for(timeout) {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.guard() })
+ Some(unsafe { self.make_guard_unchecked() })
} else {
None
}
@@ -377,7 +387,7 @@ impl<R: RawMutexTimed, T: ?Sized> Mutex<R, T> {
pub fn try_lock_until(&self, timeout: R::Instant) -> Option<MutexGuard<'_, R, T>> {
if self.raw.try_lock_until(timeout) {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.guard() })
+ Some(unsafe { self.make_guard_unchecked() })
} else {
None
}
@@ -392,7 +402,7 @@ impl<R: RawMutexTimed, T: ?Sized> Mutex<R, T> {
pub fn try_lock_arc_for(self: &Arc<Self>, timeout: R::Duration) -> Option<ArcMutexGuard<R, T>> {
if self.raw.try_lock_for(timeout) {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.guard_arc() })
+ Some(unsafe { self.make_arc_guard_unchecked() })
} else {
None
}
@@ -410,7 +420,7 @@ impl<R: RawMutexTimed, T: ?Sized> Mutex<R, T> {
) -> Option<ArcMutexGuard<R, T>> {
if self.raw.try_lock_until(timeout) {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.guard_arc() })
+ Some(unsafe { self.make_arc_guard_unchecked() })
} else {
None
}
diff --git a/vendor/lock_api/src/remutex.rs b/vendor/lock_api/src/remutex.rs
index a2f818523..74f2da343 100644
--- a/vendor/lock_api/src/remutex.rs
+++ b/vendor/lock_api/src/remutex.rs
@@ -183,8 +183,10 @@ impl<R: RawMutexFair, G: GetThreadId> RawReentrantMutex<R, G> {
if self.lock_count.get() == 1 {
let id = self.owner.load(Ordering::Relaxed);
self.owner.store(0, Ordering::Relaxed);
+ self.lock_count.set(0);
self.mutex.bump();
self.owner.store(id, Ordering::Relaxed);
+ self.lock_count.set(1);
}
}
}
@@ -287,11 +289,16 @@ impl<R, G, T> ReentrantMutex<R, G, T> {
}
impl<R: RawMutex, G: GetThreadId, T: ?Sized> ReentrantMutex<R, G, T> {
+ /// Creates a new `ReentrantMutexGuard` without checking if the lock is held.
+ ///
/// # Safety
///
- /// The lock must be held when calling this method.
+ /// This method must only be called if the thread logically holds the lock.
+ ///
+ /// Calling this function when a guard has already been produced is undefined behaviour unless
+ /// the guard was forgotten with `mem::forget`.
#[inline]
- unsafe fn guard(&self) -> ReentrantMutexGuard<'_, R, G, T> {
+ pub unsafe fn make_guard_unchecked(&self) -> ReentrantMutexGuard<'_, R, G, T> {
ReentrantMutexGuard {
remutex: &self,
marker: PhantomData,
@@ -312,7 +319,7 @@ impl<R: RawMutex, G: GetThreadId, T: ?Sized> ReentrantMutex<R, G, T> {
pub fn lock(&self) -> ReentrantMutexGuard<'_, R, G, T> {
self.raw.lock();
// SAFETY: The lock is held, as required.
- unsafe { self.guard() }
+ unsafe { self.make_guard_unchecked() }
}
/// Attempts to acquire this lock.
@@ -326,7 +333,7 @@ impl<R: RawMutex, G: GetThreadId, T: ?Sized> ReentrantMutex<R, G, T> {
pub fn try_lock(&self) -> Option<ReentrantMutexGuard<'_, R, G, T>> {
if self.raw.try_lock() {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.guard() })
+ Some(unsafe { self.make_guard_unchecked() })
} else {
None
}
@@ -400,12 +407,17 @@ impl<R: RawMutex, G: GetThreadId, T: ?Sized> ReentrantMutex<R, G, T> {
self.data.get()
}
+ /// Creates a new `ArcReentrantMutexGuard` without checking if the lock is held.
+ ///
/// # Safety
///
- /// The lock must be held before calling this method.
+ /// This method must only be called if the thread logically holds the lock.
+ ///
+ /// Calling this function when a guard has already been produced is undefined behaviour unless
+ /// the guard was forgotten with `mem::forget`.
#[cfg(feature = "arc_lock")]
#[inline]
- unsafe fn guard_arc(self: &Arc<Self>) -> ArcReentrantMutexGuard<R, G, T> {
+ pub unsafe fn make_arc_guard_unchecked(self: &Arc<Self>) -> ArcReentrantMutexGuard<R, G, T> {
ArcReentrantMutexGuard {
remutex: self.clone(),
marker: PhantomData,
@@ -421,7 +433,7 @@ impl<R: RawMutex, G: GetThreadId, T: ?Sized> ReentrantMutex<R, G, T> {
pub fn lock_arc(self: &Arc<Self>) -> ArcReentrantMutexGuard<R, G, T> {
self.raw.lock();
// SAFETY: locking guarantee is upheld
- unsafe { self.guard_arc() }
+ unsafe { self.make_arc_guard_unchecked() }
}
/// Attempts to acquire a reentrant mutex through an `Arc`.
@@ -433,7 +445,7 @@ impl<R: RawMutex, G: GetThreadId, T: ?Sized> ReentrantMutex<R, G, T> {
pub fn try_lock_arc(self: &Arc<Self>) -> Option<ArcReentrantMutexGuard<R, G, T>> {
if self.raw.try_lock() {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.guard_arc() })
+ Some(unsafe { self.make_arc_guard_unchecked() })
} else {
None
}
@@ -468,7 +480,7 @@ impl<R: RawMutexTimed, G: GetThreadId, T: ?Sized> ReentrantMutex<R, G, T> {
pub fn try_lock_for(&self, timeout: R::Duration) -> Option<ReentrantMutexGuard<'_, R, G, T>> {
if self.raw.try_lock_for(timeout) {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.guard() })
+ Some(unsafe { self.make_guard_unchecked() })
} else {
None
}
@@ -483,7 +495,7 @@ impl<R: RawMutexTimed, G: GetThreadId, T: ?Sized> ReentrantMutex<R, G, T> {
pub fn try_lock_until(&self, timeout: R::Instant) -> Option<ReentrantMutexGuard<'_, R, G, T>> {
if self.raw.try_lock_until(timeout) {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.guard() })
+ Some(unsafe { self.make_guard_unchecked() })
} else {
None
}
@@ -501,7 +513,7 @@ impl<R: RawMutexTimed, G: GetThreadId, T: ?Sized> ReentrantMutex<R, G, T> {
) -> Option<ArcReentrantMutexGuard<R, G, T>> {
if self.raw.try_lock_for(timeout) {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.guard_arc() })
+ Some(unsafe { self.make_arc_guard_unchecked() })
} else {
None
}
@@ -519,7 +531,7 @@ impl<R: RawMutexTimed, G: GetThreadId, T: ?Sized> ReentrantMutex<R, G, T> {
) -> Option<ArcReentrantMutexGuard<R, G, T>> {
if self.raw.try_lock_until(timeout) {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.guard_arc() })
+ Some(unsafe { self.make_arc_guard_unchecked() })
} else {
None
}
diff --git a/vendor/lock_api/src/rwlock.rs b/vendor/lock_api/src/rwlock.rs
index cfec59e16..cf9e8aa07 100644
--- a/vendor/lock_api/src/rwlock.rs
+++ b/vendor/lock_api/src/rwlock.rs
@@ -409,22 +409,33 @@ impl<R, T> RwLock<R, T> {
}
impl<R: RawRwLock, T: ?Sized> RwLock<R, T> {
+ /// Creates a new `RwLockReadGuard` without checking if the lock is held.
+ ///
/// # Safety
///
- /// The lock must be held when calling this method.
+ /// This method must only be called if the thread logically holds a read lock.
+ ///
+ /// This function does not increment the read count of the lock. Calling this function when a
+ /// guard has already been produced is undefined behaviour unless the guard was forgotten
+ /// with `mem::forget`.`
#[inline]
- unsafe fn read_guard(&self) -> RwLockReadGuard<'_, R, T> {
+ pub unsafe fn make_read_guard_unchecked(&self) -> RwLockReadGuard<'_, R, T> {
RwLockReadGuard {
rwlock: self,
marker: PhantomData,
}
}
+ /// Creates a new `RwLockReadGuard` without checking if the lock is held.
+ ///
/// # Safety
///
- /// The lock must be held when calling this method.
+ /// This method must only be called if the thread logically holds a write lock.
+ ///
+ /// Calling this function when a guard has already been produced is undefined behaviour unless
+ /// the guard was forgotten with `mem::forget`.
#[inline]
- unsafe fn write_guard(&self) -> RwLockWriteGuard<'_, R, T> {
+ pub unsafe fn make_write_guard_unchecked(&self) -> RwLockWriteGuard<'_, R, T> {
RwLockWriteGuard {
rwlock: self,
marker: PhantomData,
@@ -447,7 +458,7 @@ impl<R: RawRwLock, T: ?Sized> RwLock<R, T> {
pub fn read(&self) -> RwLockReadGuard<'_, R, T> {
self.raw.lock_shared();
// SAFETY: The lock is held, as required.
- unsafe { self.read_guard() }
+ unsafe { self.make_read_guard_unchecked() }
}
/// Attempts to acquire this `RwLock` with shared read access.
@@ -461,7 +472,7 @@ impl<R: RawRwLock, T: ?Sized> RwLock<R, T> {
pub fn try_read(&self) -> Option<RwLockReadGuard<'_, R, T>> {
if self.raw.try_lock_shared() {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.read_guard() })
+ Some(unsafe { self.make_read_guard_unchecked() })
} else {
None
}
@@ -479,7 +490,7 @@ impl<R: RawRwLock, T: ?Sized> RwLock<R, T> {
pub fn write(&self) -> RwLockWriteGuard<'_, R, T> {
self.raw.lock_exclusive();
// SAFETY: The lock is held, as required.
- unsafe { self.write_guard() }
+ unsafe { self.make_write_guard_unchecked() }
}
/// Attempts to lock this `RwLock` with exclusive write access.
@@ -493,7 +504,7 @@ impl<R: RawRwLock, T: ?Sized> RwLock<R, T> {
pub fn try_write(&self) -> Option<RwLockWriteGuard<'_, R, T>> {
if self.raw.try_lock_exclusive() {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.write_guard() })
+ Some(unsafe { self.make_write_guard_unchecked() })
} else {
None
}
@@ -583,24 +594,35 @@ impl<R: RawRwLock, T: ?Sized> RwLock<R, T> {
self.data.get()
}
+ /// Creates a new `RwLockReadGuard` without checking if the lock is held.
+ ///
/// # Safety
///
- /// The lock must be held when calling this method.
+ /// This method must only be called if the thread logically holds a read lock.
+ ///
+ /// This function does not increment the read count of the lock. Calling this function when a
+ /// guard has already been produced is undefined behaviour unless the guard was forgotten
+ /// with `mem::forget`.`
#[cfg(feature = "arc_lock")]
#[inline]
- unsafe fn read_guard_arc(self: &Arc<Self>) -> ArcRwLockReadGuard<R, T> {
+ pub unsafe fn make_arc_read_guard_unchecked(self: &Arc<Self>) -> ArcRwLockReadGuard<R, T> {
ArcRwLockReadGuard {
rwlock: self.clone(),
marker: PhantomData,
}
}
+ /// Creates a new `RwLockWriteGuard` without checking if the lock is held.
+ ///
/// # Safety
///
- /// The lock must be held when calling this method.
+ /// This method must only be called if the thread logically holds a write lock.
+ ///
+ /// Calling this function when a guard has already been produced is undefined behaviour unless
+ /// the guard was forgotten with `mem::forget`.
#[cfg(feature = "arc_lock")]
#[inline]
- unsafe fn write_guard_arc(self: &Arc<Self>) -> ArcRwLockWriteGuard<R, T> {
+ pub unsafe fn make_arc_write_guard_unchecked(self: &Arc<Self>) -> ArcRwLockWriteGuard<R, T> {
ArcRwLockWriteGuard {
rwlock: self.clone(),
marker: PhantomData,
@@ -616,7 +638,7 @@ impl<R: RawRwLock, T: ?Sized> RwLock<R, T> {
pub fn read_arc(self: &Arc<Self>) -> ArcRwLockReadGuard<R, T> {
self.raw.lock_shared();
// SAFETY: locking guarantee is upheld
- unsafe { self.read_guard_arc() }
+ unsafe { self.make_arc_read_guard_unchecked() }
}
/// Attempts to lock this `RwLock` with read access, through an `Arc`.
@@ -628,7 +650,7 @@ impl<R: RawRwLock, T: ?Sized> RwLock<R, T> {
pub fn try_read_arc(self: &Arc<Self>) -> Option<ArcRwLockReadGuard<R, T>> {
if self.raw.try_lock_shared() {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.read_guard_arc() })
+ Some(unsafe { self.make_arc_read_guard_unchecked() })
} else {
None
}
@@ -643,7 +665,7 @@ impl<R: RawRwLock, T: ?Sized> RwLock<R, T> {
pub fn write_arc(self: &Arc<Self>) -> ArcRwLockWriteGuard<R, T> {
self.raw.lock_exclusive();
// SAFETY: locking guarantee is upheld
- unsafe { self.write_guard_arc() }
+ unsafe { self.make_arc_write_guard_unchecked() }
}
/// Attempts to lock this `RwLock` with writ access, through an `Arc`.
@@ -655,7 +677,7 @@ impl<R: RawRwLock, T: ?Sized> RwLock<R, T> {
pub fn try_write_arc(self: &Arc<Self>) -> Option<ArcRwLockWriteGuard<R, T>> {
if self.raw.try_lock_exclusive() {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.write_guard_arc() })
+ Some(unsafe { self.make_arc_write_guard_unchecked() })
} else {
None
}
@@ -707,7 +729,7 @@ impl<R: RawRwLockTimed, T: ?Sized> RwLock<R, T> {
pub fn try_read_for(&self, timeout: R::Duration) -> Option<RwLockReadGuard<'_, R, T>> {
if self.raw.try_lock_shared_for(timeout) {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.read_guard() })
+ Some(unsafe { self.make_read_guard_unchecked() })
} else {
None
}
@@ -723,7 +745,7 @@ impl<R: RawRwLockTimed, T: ?Sized> RwLock<R, T> {
pub fn try_read_until(&self, timeout: R::Instant) -> Option<RwLockReadGuard<'_, R, T>> {
if self.raw.try_lock_shared_until(timeout) {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.read_guard() })
+ Some(unsafe { self.make_read_guard_unchecked() })
} else {
None
}
@@ -739,7 +761,7 @@ impl<R: RawRwLockTimed, T: ?Sized> RwLock<R, T> {
pub fn try_write_for(&self, timeout: R::Duration) -> Option<RwLockWriteGuard<'_, R, T>> {
if self.raw.try_lock_exclusive_for(timeout) {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.write_guard() })
+ Some(unsafe { self.make_write_guard_unchecked() })
} else {
None
}
@@ -755,7 +777,7 @@ impl<R: RawRwLockTimed, T: ?Sized> RwLock<R, T> {
pub fn try_write_until(&self, timeout: R::Instant) -> Option<RwLockWriteGuard<'_, R, T>> {
if self.raw.try_lock_exclusive_until(timeout) {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.write_guard() })
+ Some(unsafe { self.make_write_guard_unchecked() })
} else {
None
}
@@ -773,7 +795,7 @@ impl<R: RawRwLockTimed, T: ?Sized> RwLock<R, T> {
) -> Option<ArcRwLockReadGuard<R, T>> {
if self.raw.try_lock_shared_for(timeout) {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.read_guard_arc() })
+ Some(unsafe { self.make_arc_read_guard_unchecked() })
} else {
None
}
@@ -791,7 +813,7 @@ impl<R: RawRwLockTimed, T: ?Sized> RwLock<R, T> {
) -> Option<ArcRwLockReadGuard<R, T>> {
if self.raw.try_lock_shared_until(timeout) {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.read_guard_arc() })
+ Some(unsafe { self.make_arc_read_guard_unchecked() })
} else {
None
}
@@ -809,7 +831,7 @@ impl<R: RawRwLockTimed, T: ?Sized> RwLock<R, T> {
) -> Option<ArcRwLockWriteGuard<R, T>> {
if self.raw.try_lock_exclusive_for(timeout) {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.write_guard_arc() })
+ Some(unsafe { self.make_arc_write_guard_unchecked() })
} else {
None
}
@@ -827,7 +849,7 @@ impl<R: RawRwLockTimed, T: ?Sized> RwLock<R, T> {
) -> Option<ArcRwLockWriteGuard<R, T>> {
if self.raw.try_lock_exclusive_until(timeout) {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.write_guard_arc() })
+ Some(unsafe { self.make_arc_write_guard_unchecked() })
} else {
None
}
@@ -854,7 +876,7 @@ impl<R: RawRwLockRecursive, T: ?Sized> RwLock<R, T> {
pub fn read_recursive(&self) -> RwLockReadGuard<'_, R, T> {
self.raw.lock_shared_recursive();
// SAFETY: The lock is held, as required.
- unsafe { self.read_guard() }
+ unsafe { self.make_read_guard_unchecked() }
}
/// Attempts to acquire this `RwLock` with shared read access.
@@ -871,7 +893,7 @@ impl<R: RawRwLockRecursive, T: ?Sized> RwLock<R, T> {
pub fn try_read_recursive(&self) -> Option<RwLockReadGuard<'_, R, T>> {
if self.raw.try_lock_shared_recursive() {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.read_guard() })
+ Some(unsafe { self.make_read_guard_unchecked() })
} else {
None
}
@@ -886,7 +908,7 @@ impl<R: RawRwLockRecursive, T: ?Sized> RwLock<R, T> {
pub fn read_arc_recursive(self: &Arc<Self>) -> ArcRwLockReadGuard<R, T> {
self.raw.lock_shared_recursive();
// SAFETY: locking guarantee is upheld
- unsafe { self.read_guard_arc() }
+ unsafe { self.make_arc_read_guard_unchecked() }
}
/// Attempts to lock this `RwLock` with shared read access, through an `Arc`.
@@ -898,7 +920,7 @@ impl<R: RawRwLockRecursive, T: ?Sized> RwLock<R, T> {
pub fn try_read_recursive_arc(self: &Arc<Self>) -> Option<ArcRwLockReadGuard<R, T>> {
if self.raw.try_lock_shared_recursive() {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.read_guard_arc() })
+ Some(unsafe { self.make_arc_read_guard_unchecked() })
} else {
None
}
@@ -923,7 +945,7 @@ impl<R: RawRwLockRecursiveTimed, T: ?Sized> RwLock<R, T> {
) -> Option<RwLockReadGuard<'_, R, T>> {
if self.raw.try_lock_shared_recursive_for(timeout) {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.read_guard() })
+ Some(unsafe { self.make_read_guard_unchecked() })
} else {
None
}
@@ -942,7 +964,7 @@ impl<R: RawRwLockRecursiveTimed, T: ?Sized> RwLock<R, T> {
) -> Option<RwLockReadGuard<'_, R, T>> {
if self.raw.try_lock_shared_recursive_until(timeout) {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.read_guard() })
+ Some(unsafe { self.make_read_guard_unchecked() })
} else {
None
}
@@ -960,7 +982,7 @@ impl<R: RawRwLockRecursiveTimed, T: ?Sized> RwLock<R, T> {
) -> Option<ArcRwLockReadGuard<R, T>> {
if self.raw.try_lock_shared_recursive_for(timeout) {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.read_guard_arc() })
+ Some(unsafe { self.make_arc_read_guard_unchecked() })
} else {
None
}
@@ -978,7 +1000,7 @@ impl<R: RawRwLockRecursiveTimed, T: ?Sized> RwLock<R, T> {
) -> Option<ArcRwLockReadGuard<R, T>> {
if self.raw.try_lock_shared_recursive_until(timeout) {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.read_guard_arc() })
+ Some(unsafe { self.make_arc_read_guard_unchecked() })
} else {
None
}
@@ -986,11 +1008,17 @@ impl<R: RawRwLockRecursiveTimed, T: ?Sized> RwLock<R, T> {
}
impl<R: RawRwLockUpgrade, T: ?Sized> RwLock<R, T> {
+ /// Creates a new `RwLockUpgradableReadGuard` without checking if the lock is held.
+ ///
/// # Safety
///
- /// The lock must be held when calling this method.
+ /// This method must only be called if the thread logically holds an upgradable read lock.
+ ///
+ /// This function does not increment the read count of the lock. Calling this function when a
+ /// guard has already been produced is undefined behaviour unless the guard was forgotten
+ /// with `mem::forget`.`
#[inline]
- unsafe fn upgradable_guard(&self) -> RwLockUpgradableReadGuard<'_, R, T> {
+ pub unsafe fn make_upgradable_guard_unchecked(&self) -> RwLockUpgradableReadGuard<'_, R, T> {
RwLockUpgradableReadGuard {
rwlock: self,
marker: PhantomData,
@@ -1010,7 +1038,7 @@ impl<R: RawRwLockUpgrade, T: ?Sized> RwLock<R, T> {
pub fn upgradable_read(&self) -> RwLockUpgradableReadGuard<'_, R, T> {
self.raw.lock_upgradable();
// SAFETY: The lock is held, as required.
- unsafe { self.upgradable_guard() }
+ unsafe { self.make_upgradable_guard_unchecked() }
}
/// Attempts to acquire this `RwLock` with upgradable read access.
@@ -1024,18 +1052,26 @@ impl<R: RawRwLockUpgrade, T: ?Sized> RwLock<R, T> {
pub fn try_upgradable_read(&self) -> Option<RwLockUpgradableReadGuard<'_, R, T>> {
if self.raw.try_lock_upgradable() {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.upgradable_guard() })
+ Some(unsafe { self.make_upgradable_guard_unchecked() })
} else {
None
}
}
+ /// Creates a new `ArcRwLockUpgradableReadGuard` without checking if the lock is held.
+ ///
/// # Safety
///
- /// The lock must be held when calling this method.
+ /// This method must only be called if the thread logically holds an upgradable read lock.
+ ///
+ /// This function does not increment the read count of the lock. Calling this function when a
+ /// guard has already been produced is undefined behaviour unless the guard was forgotten
+ /// with `mem::forget`.`
#[cfg(feature = "arc_lock")]
#[inline]
- unsafe fn upgradable_guard_arc(self: &Arc<Self>) -> ArcRwLockUpgradableReadGuard<R, T> {
+ pub unsafe fn make_upgradable_arc_guard_unchecked(
+ self: &Arc<Self>,
+ ) -> ArcRwLockUpgradableReadGuard<R, T> {
ArcRwLockUpgradableReadGuard {
rwlock: self.clone(),
marker: PhantomData,
@@ -1051,7 +1087,7 @@ impl<R: RawRwLockUpgrade, T: ?Sized> RwLock<R, T> {
pub fn upgradable_read_arc(self: &Arc<Self>) -> ArcRwLockUpgradableReadGuard<R, T> {
self.raw.lock_upgradable();
// SAFETY: locking guarantee is upheld
- unsafe { self.upgradable_guard_arc() }
+ unsafe { self.make_upgradable_arc_guard_unchecked() }
}
/// Attempts to lock this `RwLock` with upgradable read access, through an `Arc`.
@@ -1063,7 +1099,7 @@ impl<R: RawRwLockUpgrade, T: ?Sized> RwLock<R, T> {
pub fn try_upgradable_read_arc(self: &Arc<Self>) -> Option<ArcRwLockUpgradableReadGuard<R, T>> {
if self.raw.try_lock_upgradable() {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.upgradable_guard_arc() })
+ Some(unsafe { self.make_upgradable_arc_guard_unchecked() })
} else {
None
}
@@ -1084,7 +1120,7 @@ impl<R: RawRwLockUpgradeTimed, T: ?Sized> RwLock<R, T> {
) -> Option<RwLockUpgradableReadGuard<'_, R, T>> {
if self.raw.try_lock_upgradable_for(timeout) {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.upgradable_guard() })
+ Some(unsafe { self.make_upgradable_guard_unchecked() })
} else {
None
}
@@ -1103,7 +1139,7 @@ impl<R: RawRwLockUpgradeTimed, T: ?Sized> RwLock<R, T> {
) -> Option<RwLockUpgradableReadGuard<'_, R, T>> {
if self.raw.try_lock_upgradable_until(timeout) {
// SAFETY: The lock is held, as required.
- Some(unsafe { self.upgradable_guard() })
+ Some(unsafe { self.make_upgradable_guard_unchecked() })
} else {
None
}
@@ -1121,7 +1157,7 @@ impl<R: RawRwLockUpgradeTimed, T: ?Sized> RwLock<R, T> {
) -> Option<ArcRwLockUpgradableReadGuard<R, T>> {
if self.raw.try_lock_upgradable_for(timeout) {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.upgradable_guard_arc() })
+ Some(unsafe { self.make_upgradable_arc_guard_unchecked() })
} else {
None
}
@@ -1139,7 +1175,7 @@ impl<R: RawRwLockUpgradeTimed, T: ?Sized> RwLock<R, T> {
) -> Option<ArcRwLockUpgradableReadGuard<R, T>> {
if self.raw.try_lock_upgradable_until(timeout) {
// SAFETY: locking guarantee is upheld
- Some(unsafe { self.upgradable_guard_arc() })
+ Some(unsafe { self.make_upgradable_arc_guard_unchecked() })
} else {
None
}
@@ -2025,7 +2061,7 @@ impl<'a, R: RawRwLockUpgradeDowngrade + 'a, T: ?Sized + 'a> RwLockUpgradableRead
// Safety: We just upgraded the lock, so we have mutable access to the data.
// This will restore the state the lock was in at the start of the function.
- defer!(unsafe { self.rwlock.raw.downgrade_upgradable() });
+ defer!(unsafe { self.rwlock.raw.downgrade_to_upgradable() });
// Safety: We upgraded the lock, so we have mutable access to the data.
// When this function returns, whether by drop or panic,
@@ -2047,7 +2083,7 @@ impl<'a, R: RawRwLockUpgradeDowngrade + 'a, T: ?Sized + 'a> RwLockUpgradableRead
if unsafe { self.rwlock.raw.try_upgrade() } {
// Safety: We just upgraded the lock, so we have mutable access to the data.
// This will restore the state the lock was in at the start of the function.
- defer!(unsafe { self.rwlock.raw.downgrade_upgradable() });
+ defer!(unsafe { self.rwlock.raw.downgrade_to_upgradable() });
// Safety: We upgraded the lock, so we have mutable access to the data.
// When this function returns, whether by drop or panic,