Skip to content

Commit 16c5ba6

Browse files
authored
Unrolled build for #144022
Rollup merge of #144022 - connortsui20:sync_nonpoison, r=tgross35 Implementation: `#[feature(sync_nonpoison)]`, `#[feature(nonpoison_mutex)]` Continuation of #134663 Tracking Issue: #134645 This PR implements a new `sync/nonpoison` module, as well as the `nonpoison` variant of the `Mutex` lock. There are 2 main changes here, the first is the new `nonpoison::mutex` module, and the second is the `mutex` integration tests. For the `nonpoison::mutex` module, I did my best to align it with the current state of the `poison::mutex` module. This means that several unstable features (`mapped_lock_guards`, `lock_value_accessors`, and `mutex_data_ptr`) are also in the new `nonpoison::mutex` module, under their respective feature gates. Everything else in that file is under the correct feature gate (`#[unstable(feature = "nonpoison_mutex", issue = "134645")]`). Everything in the `nonpoison::mutex` file is essentially identical in spirit, as we are simply removing the error case from the original `poison::mutex`. The second big change is in the integration tests. I created a macro called that allows us to duplicate tests that are "generic" over the different mutex types, in that the poison mutex is always `unwrap`ped. ~~I think that there is an argument against doing this, as it can make the tests a bit harder to understand (and language server capabilities are weaker within macros), but I think the benefit of code deduplication here is worth it. Note that it is definitely possible to generalize this (with a few tweaks) to testing the other `nonpoison` locks when they eventually get implemented, but I'll leave that for a later discussion.~~
2 parents 5529041 + d073d29 commit 16c5ba6

25 files changed

+1070
-234
lines changed

library/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

library/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)