Skip to content

Commit 42d8ab4

Browse files
connortsui20Aandrebatgross35
committed
add nonpoison::mutex implementation
Adds the equivalent `nonpoison` types to the `poison::mutex` module. These types and implementations are gated under the `nonpoison_mutex` feature gate. Also blesses the ui tests that now have a name conflicts (because these types no longer have unique names). The full path distinguishes the different types. Co-authored-by: Aandreba <[email protected]> Co-authored-by: Trevor Gross <[email protected]>
1 parent bc089b3 commit 42d8ab4

File tree

3 files changed

+650
-0
lines changed

3 files changed

+650
-0
lines changed

std/src/sync/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ pub use self::poison::{MappedMutexGuard, MappedRwLockReadGuard, MappedRwLockWrit
225225
pub mod mpmc;
226226
pub mod mpsc;
227227

228+
#[unstable(feature = "sync_nonpoison", issue = "134645")]
229+
pub mod nonpoison;
228230
#[unstable(feature = "sync_poison_mod", issue = "134646")]
229231
pub mod poison;
230232

std/src/sync/nonpoison.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//! Non-poisoning synchronous locks.
2+
//!
3+
//! The difference from the locks in the [`poison`] module is that the locks in this module will not
4+
//! become poisoned when a thread panics while holding a guard.
5+
//!
6+
//! [`poison`]: super::poison
7+
8+
use crate::fmt;
9+
10+
/// A type alias for the result of a nonblocking locking method.
11+
#[unstable(feature = "sync_nonpoison", issue = "134645")]
12+
pub type TryLockResult<Guard> = Result<Guard, WouldBlock>;
13+
14+
/// A lock could not be acquired at this time because the operation would otherwise block.
15+
#[unstable(feature = "sync_nonpoison", issue = "134645")]
16+
pub struct WouldBlock;
17+
18+
#[unstable(feature = "sync_nonpoison", issue = "134645")]
19+
impl fmt::Debug for WouldBlock {
20+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21+
"WouldBlock".fmt(f)
22+
}
23+
}
24+
25+
#[unstable(feature = "sync_nonpoison", issue = "134645")]
26+
impl fmt::Display for WouldBlock {
27+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28+
"try_lock failed because the operation would block".fmt(f)
29+
}
30+
}
31+
32+
#[unstable(feature = "mapped_lock_guards", issue = "117108")]
33+
pub use self::mutex::MappedMutexGuard;
34+
#[unstable(feature = "nonpoison_mutex", issue = "134645")]
35+
pub use self::mutex::{Mutex, MutexGuard};
36+
37+
mod mutex;

0 commit comments

Comments
 (0)