Commit Graph

28 Commits

Author SHA1 Message Date
Connor Tsui
b8ee38b79e move WaitTimeoutResult up to mod.rs
Since `WaitTimeoutResult` is poison-agnostic, we want to use the same
type for both variants of `Condvar`.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-08-23 09:20:47 -04:00
Connor Tsui
3bdc228c10 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 <aandreba@gmail.com>
Co-authored-by: Trevor Gross <tmgross@umich.edu>
2025-07-29 10:32:15 +02:00
Frank King
5016467a23 Implement UniqueArc 2025-03-22 15:14:49 +08:00
Pavel Grigorenko
ee2ad4dfb1 Move some things to std::sync::poison and reexport them in std::sync 2025-01-02 15:21:41 +03:00
Obei Sideg
041e76b7cd Add multi-producer, multi-consumer channel (mpmc) 2024-09-30 20:43:51 +03:00
Michael Goulet
c682aa162b Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
Obei Sideg
3b0ce1bc33 Update tests for hidden references to mutable static 2024-09-13 14:10:56 +03:00
Nicholas Nethercote
84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Jubilee Young
b8eb6ad032 std: suggest OnceLock over Once 2024-06-15 00:09:03 -07:00
Pietro Albini
be9e27e490 replace version placeholder 2024-06-11 16:52:02 +02:00
Jubilee Young
fdb96f2123 Differ LazyLock vs. OnceLock in std::sync overview 2024-06-02 22:53:41 -07:00
Peter Jaszkowiak
4913ab8f77 Stabilize LazyCell and LazyLock (lazy_cell) 2024-02-20 20:55:13 -07:00
Matthias Krüger
332b9be7a1 Rollup merge of #110543 - joboet:reentrant_lock, r=m-ou-se
Make `ReentrantLock` public

Implements the ACP rust-lang/libs-team#193.

``@rustbot`` label +T-libs-api +S-waiting-on-ACP
2024-02-29 00:16:58 +01:00
joboet
2aa8a1d45c std: make ReentrantLock public 2024-02-23 20:43:27 +01:00
Zachary S
20fa3a0d8f Fix Condvar typo, add public re-exports of Mapped*Guard. 2023-12-05 16:39:03 -06:00
Pietro Albini
4e04da6183 replace version placeholders 2023-04-28 08:47:55 -07:00
Trevor Gross
d1b28b75d2 Documentation updates to better share the purpose of OnceCell/OnceLock 2023-03-29 18:04:44 -04:00
Trevor Gross
dc4ba57566 Stabilize a portion of 'once_cell'
Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try'
2023-03-29 18:04:44 -04:00
joboet
c1cced8d04 std: optimize LazyLock size 2023-01-26 16:16:03 +01:00
joboet
c66494474c std: move ReentrantMutex to sync 2022-11-14 14:25:44 +01:00
Ibraheem Ahmed
a43da5a097 initial port of crossbeam-channel 2022-11-09 23:18:06 -05:00
Matthias Krüger
0e71d1f237 Rollup merge of #97629 - guswynn:exclusive_struct, r=m-ou-se
[core] add `Exclusive` to sync

(discussed here: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Adding.20.60SyncWrapper.60.20to.20std)

`Exclusive` is a wrapper that exclusively allows mutable access to the inner value if you have exclusive access to the wrapper. It acts like a compile time mutex, and hold an unconditional `Sync` implementation.

## Justification for inclusion into std
- This wrapper unblocks actual problems:
  - The example that I hit was a vector of `futures::future::BoxFuture`'s causing a central struct in a script to be non-`Sync`. To work around it, you either write really difficult code, or wrap the futures in a needless mutex.
- Easy to maintain: this struct is as simple as a wrapper can get, and its `Sync` implementation has very clear reasoning
- Fills a gap: `&/&mut` are to `RwLock` as `Exclusive` is to `Mutex`

## Public Api
```rust
// core::sync
#[derive(Default)]
struct Exclusive<T: ?Sized> { ... }

impl<T: ?Sized> Sync for Exclusive {}

impl<T> Exclusive<T> {
    pub const fn new(t: T) -> Self;
    pub const fn into_inner(self) -> T;
}

impl<T: ?Sized> Exclusive<T> {
    pub const fn get_mut(&mut self) -> &mut T;
    pub const fn get_pin_mut(Pin<&mut self>) -> Pin<&mut T>;
    pub const fn from_mut(&mut T) -> &mut Exclusive<T>;
    pub const fn from_pin_mut(Pin<&mut T>) -> Pin<&mut Exclusive<T>>;
}

impl<T: Future> Future for Exclusive { ... }

impl<T> From<T> for Exclusive<T> { ... }
impl<T: ?Sized> Debug for Exclusive { ... }
```

## Naming
This is a big bikeshed, but I felt that `Exclusive` captured its general purpose quite well.

## Stability and location
As this is so simple, it can be in `core`. I feel that it can be stabilized quite soon after it is merged, if the libs teams feels its reasonable to add. Also, I don't really know how unstable feature work in std/core's codebases, so I might need help fixing them

## Tips for review
The docs probably are the thing that needs to be reviewed! I tried my best, but I'm sure people have more experience than me writing docs for `Core`

### Implementation:
The API is mostly pulled from https://docs.rs/sync_wrapper/latest/sync_wrapper/struct.SyncWrapper.html (which is apache 2.0 licenesed), and the implementation is trivial:
- its an unsafe justification for pinning
- its an unsafe justification for the `Sync` impl (mostly reasoned about by ````@danielhenrymantilla```` here: https://github.com/Actyx/sync_wrapper/pull/2)
- and forwarding impls, starting with derivable ones and `Future`
2022-06-30 19:55:50 +02:00
Gus Wynn
029f9aa3bf add tracking issue for exclusive 2022-06-23 08:52:13 -07:00
Maybe Waffle
c1a2db3372 Move/rename lazy::Sync{OnceCell,Lazy} to sync::{Once,Lazy}Lock 2022-06-16 19:54:42 +04:00
Gus Wynn
63d1c86230 [core] add Exclusive to sync 2022-06-07 13:10:50 -07:00
T-O-R-U-S
72a25d05bf Use implicit capture syntax in format_args
This updates the standard library's documentation to use the new syntax. The
documentation is worthwhile to update as it should be more idiomatic
(particularly for features like this, which are nice for users to get acquainted
with). The general codebase is likely more hassle than benefit to update: it'll
hurt git blame, and generally updates can be done by folks updating the code if
(and when) that makes things more readable with the new format.

A few places in the compiler and library code are updated (mostly just due to
already having been done when this commit was first authored).
2022-03-10 10:23:40 -05:00
Christiaan Dirkx
9cabbd0afc Move sys_common::poison to sync::poison 2021-04-22 10:27:21 +02:00
mark
2c31b45ae8 mv std libs to library/ 2020-07-27 19:51:13 -05:00