summary refs log tree commit diff
path: root/library/std/src/sync/mutex.rs
AgeCommit message (Collapse)AuthorLines
2022-06-19Auto merge of #97791 - m-ou-se:const-locks, r=m-ou-sebors-1/+3
Make {Mutex, Condvar, RwLock}::new() const. This makes it possible to have `static M: Mutex<_> = Mutex::new(..);` 🎉 Our implementations [on Linux](https://github.com/rust-lang/rust/pull/95035), [on Windows](https://github.com/rust-lang/rust/pull/77380), and various BSDs and some tier 3 platforms have already been using a non-allocating const-constructible implementation. As of https://github.com/rust-lang/rust/pull/97647, the remaining platforms (most notably macOS) now have a const-constructible implementation as well. This means we can finally make these functions publicly const. Tracking issue: https://github.com/rust-lang/rust/issues/93740
2022-06-09Avoid `thread::panicking()` in non-poisoning methods of `Mutex` and `RwLock`Josh Stone-3/+3
`Mutex::lock()` and `RwLock::write()` are poison-guarded against panics, in that they set the poison flag if a panic occurs while they're locked. But if we're already in a panic (`thread::panicking()`), they leave the poison flag alone. That check is a bit of a waste for methods that never set the poison flag though, namely `get_mut()`, `into_inner()`, and `RwLock::read()`. These use-cases are now split to avoid that unnecessary call.
2022-06-07Update library/std/src/sync/mutex.rsDylan DPC-1/+1
Co-authored-by: Weiyi Wang <wwylele@gmail.com>
2022-06-07Remove confusing sentence from `Mutex` docsNilstrieb-5/+4
The docs were saying something about "statically initializing" the mutex, and it's not clear what this means. Remove that part to avoid confusion.
2022-06-06Make {Mutex, Condvar, RwLock}::new() const.Mara Bos-0/+1
2022-06-06Make all {Mutex, Condvar, RwLock}::new #[inline].Mara Bos-1/+2
2022-05-20Auto merge of #96422 - tmccombs:mutex-unpoison, r=m-ou-sebors-0/+39
Add functions to un-poison Mutex and RwLock See discussion at https://internals.rust-lang.org/t/unpoisoning-a-mutex/16521/3
2022-05-20Remove references to guards in documentation for clear_poisonThayne McCombs-5/+5
2022-05-19Change clear_poison to take the lock instead of a guardThayne McCombs-4/+9
2022-05-06Mark locks in std lib with clippy::has_significant_dropPreston From-0/+1
2022-04-27Add tracking issue number for mutex_unpoisonThayne McCombs-1/+1
2022-04-26Add functions to un-poison Mutex and RwLockThayne McCombs-0/+34
See discussion at https://internals.rust-lang.org/t/unpoisoning-a-mutex/16521/3
2022-01-28update cfg(bootstrap)sPietro Albini-5/+2
2021-10-03Practice diagnostic message conventionHirochika Matsumoto-1/+1
2021-10-02Make diangostic item names consistentCameron Steffen-1/+1
2021-09-28ref/refmutGus Wynn-1/+1
2021-09-27lock typesGus Wynn-0/+6
2021-07-01Move Mutex::unlock to T: ?SizedMark Mansi-20/+20
2021-05-24minor rewording after reviewTaylor Yu-2/+2
Use "the `WouldBlock` error" instead of "the error `WouldBlock`", etc.
2021-05-20doc: clarify Mutex::try_lock, etc. errorsTaylor Yu-2/+8
Clarify error returns from Mutex::try_lock, RwLock::try_read, RwLock::try_write to make it more obvious that both poisoning and the lock being already locked are possible errors.
2021-04-28Simplify `Mutex::into_inner`Benoît du Garreau-19/+2
2021-04-22Move `sys_common::poison` to `sync::poison`Christiaan Dirkx-1/+1
2021-03-27Improve Debug implementations of Mutex and RwLock.Mara Bos-4/+8
They now show the poison flag and use debug_non_exhaustive.
2021-02-18add Mutex::unlockmark-0/+20
2020-10-07(docs): make mutex error comment consistent with codebaseSteve Manuel-1/+1
2020-09-27Split sys_common::Mutex in StaticMutex and MovableMutex.Mara Bos-26/+4
The (unsafe) Mutex from sys_common had a rather complicated interface. You were supposed to call init() manually, unless you could guarantee it was neither moved nor used reentrantly. Calling `destroy()` was also optional, although it was unclear if 1) resources might be leaked or not, and 2) if destroy() should only be called when `init()` was called. This allowed for a number of interesting (confusing?) different ways to use this Mutex, all captured in a single type. In practice, this type was only ever used in two ways: 1. As a static variable. In this case, neither init() nor destroy() are called. The variable is never moved, and it is never used reentrantly. It is only ever locked using the LockGuard, never with raw_lock. 2. As a Boxed variable. In this case, both init() and destroy() are called, it will be moved and possibly used reentrantly. No other combinations are used anywhere in `std`. This change simplifies things by splitting this Mutex type into two types matching the two use cases: StaticMutex and MovableMutex. The interface of both new types is now both safer and simpler. The first one does not call nor expose init/destroy, and the second one calls those automatically in its new() and Drop functions. Also, the locking functions of MovableMutex are no longer unsafe.
2020-09-20Replace unneeded `unsafe` calls to `.get()` with calls to `.get_mut()`Daniel Henry-Mantilla-3/+1
2020-09-06Auto merge of #76128 - poliorcetics:doc-use-arc-clone, r=KodrAusbors-4/+4
Use Arc::clone and Rc::clone in documentation This PR replaces uses of `x.clone()` by `Rc::clone(&x)` (or `Arc::clone(&x)`) to better match the documentation for those types. @rustbot modify labels: T-doc
2020-08-31std: move "mod tests/benches" to separate filesLzu Tao-242/+3
Also doing fmt inplace as requested.
2020-08-30Move to Arc::clone(&x) over x.clone() in library/stdAlexis Bourget-4/+4
2020-08-22Use intra-doc-links in `std::sync::*`LeSeulArtichaut-16/+8
2020-07-27mv std libs to library/mark-0/+767