about summary refs log tree commit diff
path: root/library/std/src/sync/rwlock.rs
AgeCommit message (Collapse)AuthorLines
2025-01-02Move some things to `std::sync::poison` and reexport them in `std::sync`Pavel Grigorenko-1205/+0
2024-11-30Add value accessor methods to `Mutex` and `RwLock`EFanZh-13/+115
2024-11-16add `downgrade` method onto `RwLockWriteGuard`Connor Tsui-4/+70
2024-09-29Fix std tests for wasm32-wasip2 targetNicola Krumschmidt-1/+1
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-07-26Fix doc nitsJohn Arundel-2/+2
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-14std: Unsafe-wrap std::syncJubilee Young-1/+1
2024-03-26Update `RwLock` deadlock example to not use shadowingTrevor Gross-6/+7
Tweak variable names in the deadlock example to remove any potential confusion that the behavior is somehow shadowing-related.
2024-03-22docs(sync): normalize dot in fn summariesMultisampledNight-1/+1
2024-03-12std: move `Once` implementations to `sys`joboet-1/+1
2024-02-25Auto merge of #117107 - zachs18:mapped-mutex-guard, r=Amanieubors-2/+431
Implement `MappedMutexGuard`, `MappedRwLockReadGuard`, and `MappedRwLockWriteGuard`. ACP: https://github.com/rust-lang/libs-team/issues/260 Tracking issue: https://github.com/rust-lang/rust/issues/117108 <details> <summary> (Outdated) </summary> `MutexState`/`RwLockState` structs ~~Having `sys::(Mutex|RwLock)` and `poison::Flag` as separate fields in the `Mutex`/`RwLock` would require `MappedMutexGuard`/`MappedRwLockWriteGuard` to hold an additional pointer, so I combined the two fields into a `MutexState`/`RwLockState` struct. This should not noticeably affect perf or layout, but requires an additional field projection when accessing the former `.inner` or `.poison` fields (now `.state.inner` and `.state.poison`).~~ If this is not desired, then `MappedMutexGuard`/`MappedRwLockWriteGuard` can instead hold separate pointers to the two fields. </details> The doc-comments are mostly copied from the existing `*Guard` doc-comments, with some parts from `lock_api::Mapped*Guard`'s doc-comments. Unresolved question: Are more tests needed?
2024-02-08Bump version placeholdersMark Rousskov-1/+1
2024-01-10Stabilize mutex_unpoison featureThayne McCombs-3/+1
Closes #96469 @rustbot +T-libs-api
2023-12-05fmtZachary S-4/+1
2023-12-05Specify behavior if the closure passed to *Guard::*map panics.Zachary S-40/+116
2023-12-05Add comment about `Mapped(Mutex|RwLockWrite)Guard` variance.Zachary S-23/+27
2023-12-05Implmement `MappedRwLock(Read|Write)Guard`.Zachary S-3/+355
2023-10-24Add T: ?Sized to RwLock*Guards' Debug impls.Zachary S-2/+2
2023-09-19Replace 'mutex' with 'lock' in RwLock documentationKriskras99-2/+2
When copying the documentation for `clear_poison` from Mutex, not every occurence of 'mutex' was replaced with 'lock'.
2023-04-19std: make `Debug` representations of `[Lazy, Once]*[Cell, Lock]` consistent ↵joboet-7/+1
with `Mutex` and `RwLock` `Mutex` prints `<locked>` as a field value when its inner value cannot be accessed, but the lazy types print a fixed string like "`OnceCell(Uninit)`". This could cause confusion if the inner type is a unit type named `Uninit` and does not respect the pretty-printing flag. With this change, the format message is now "`OnceCell(<uninit>)`", consistent with `Mutex`.
2022-11-06std: remove lock wrappers in `sys_common`joboet-8/+4
2022-10-11Rollup merge of #102277 - mgeisler:rwlock, r=m-ou-seYuki Okushi-31/+32
Consistently write `RwLock` Before the documentation sometimes referred to an "rwlock" and sometimes to "`RwLock`".
2022-09-27Address feedbackmejrs-0/+1
2022-09-25Consistently write `RwLock`Martin Geisler-31/+32
Before the documentation sometimes referred to an "rwlock" and sometimes to "`RwLock`".
2022-09-02Rollup merge of #97739 - a2aaron:let_underscore, r=estebankGuillaume Gomez-0/+2
Uplift the `let_underscore` lints from clippy into rustc. This PR resolves #97241. This PR adds three lints from clippy--`let_underscore_drop`, `let_underscore_lock`, and `let_underscore_must_use`, which are meant to capture likely-incorrect uses of `let _ = ...` bindings (in particular, doing this on a type with a non-trivial `Drop` causes the `Drop` to occur immediately, instead of at the end of the scope. For a type like `MutexGuard`, this effectively releases the lock immediately, which is almost certainly the wrong behavior) In porting the lints from clippy I had to copy over a bunch of utility functions from `clippy_util` that these lints also relied upon. Is that the right approach? Note that I've set the `must_use` and `drop` lints to Allow by default and set `lock` to Deny by default (this matches the same settings that clippy has). In talking with `@estebank` he informed me to do a Crater run (I am not sure what type of Crater run to request here--I think it's just "check only"?) On the linked issue, there's some discussion about using `must_use` and `Drop` together as a heuristic for when to warn--I did not implement this yet. r? `@estebank`
2022-06-25Auto merge of #96820 - r-raymond:master, r=cuviperbors-4/+24
Make RwLockReadGuard covariant Hi, first time contributor here, if anything is not as expected, please let me know. `RwLockReadGoard`'s type constructor is invariant. Since it behaves like a smart pointer to an immutable reference, there is no reason that it should not be covariant. Take e.g. ``` fn test_read_guard_covariance() { fn do_stuff<'a>(_: RwLockReadGuard<'_, &'a i32>, _: &'a i32) {} let j: i32 = 5; let lock = RwLock::new(&j); { let i = 6; do_stuff(lock.read().unwrap(), &i); } drop(lock); } ``` where the compiler complains that &i doesn't live long enough. If `RwLockReadGuard` is covariant, then the above code is accepted because the lifetime can be shorter than `'a`. In order for `RwLockReadGuard` to be covariant, it can't contain a full reference to the `RwLock`, which can never be covariant (because it exposes a mutable reference to the underlying data structure). By reducing the data structure to the required pieces of `RwLock`, the rest falls in place. If there is a better way to do a test that tests successful compilation, please let me know. Fixes #80392
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-19Add comment explaining why we use NonNullRobin Raymond-0/+4
2022-06-19Add safety commentsRobin Raymond-6/+9
2022-06-19Documentation typoRobin Raymond-1/+1
2022-06-19*const to NonNull plus documentationRobin Raymond-3/+12
2022-06-19Address commentsRobin Raymond-3/+3
2022-06-19More formattingRobin Raymond-1/+1
2022-06-19FormattingRobin Raymond-1/+4
2022-06-19Make RwLockReadGuard covariantRobin Raymond-4/+5
2022-06-09Avoid `thread::panicking()` in non-poisoning methods of `Mutex` and `RwLock`Josh Stone-4/+4
`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-06Make {Mutex, Condvar, RwLock}::new() const.Mara Bos-0/+1
2022-06-06Make all {Mutex, Condvar, RwLock}::new #[inline].Mara Bos-1/+2
2022-06-05Add diagnostic items to MutexGuard and RwLock GuardsAaron Kofsky-0/+2
I forgot to add the diagnostic to the actual types in `std` earlier.
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/+2
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-04-06Rename RWLock to RwLock in std::sys.Mara Bos-2/+2
2022-01-28update cfg(bootstrap)sPietro Albini-10/+4
2021-10-03Practice diagnostic message conventionHirochika Matsumoto-2/+2
2021-09-28ref/refmutGus Wynn-1/+1
2021-09-27lock typesGus Wynn-0/+12