summaryrefslogtreecommitdiffstats
path: root/tokio/src/sync
AgeCommit message (Collapse)Author
2020-12-12sync: add blocking_recv method to UnboundedReceiver, similar to ↵HEADmasterSunjay Varma
Receiver::blocking_recv (#3262)
2020-12-10sync: make TryAcquireError public (#3250)Alice Ryhl
The [`Semaphore::try_acquire`][1] method currently returns a private error type. [1]: https://docs.rs/tokio/0.3/tokio/sync/struct.Semaphore.html#method.try_acquire
2020-12-10watch: fix spurious wakeup (#3234)Alice Ryhl
Co-authored-by: @tijsvd
2020-12-02sync: make add_permits panic with usize::MAX >> 3 permits (#3188)Blas Rodriguez Irizar
2020-11-16sync: add `Notify::notify_waiters` (#3098)Zahari Dichev
This PR makes `Notify::notify_waiters` public. The method already exists, but it changes the way `notify_waiters`, is used. Previously in order for the consumer to register interest, in a notification triggered by `notify_waiters`, the `Notified` future had to be polled. This introduced friction when using the api as the future had to be pinned before polled. This change introduces a counter that tracks how many times `notified_waiters` has been called. Upon creation of the future the number of times is loaded. When first polled the future compares this number with the count state of the `Notify` type. This avoids the need for registering the waiter upfront. Fixes: #3066
2020-11-10sync: add acquire_many and try_acquire_many to `Sempahore` (#3067)Darius Carrier
Fixes: #1550
2020-10-26sync: make oneshot::Sender::poll_closed public again (#3032)Sean McArthur
2020-10-26oneshot: update closed() docs to use tokio::select! (#3050)Alice Ryhl
2020-10-23sync: add mem::forget to RwLockWriteGuard::downgrade. (#2957)Zahari Dichev
Currently when `RwLockWriteGuard::downgrade` the `MAX_READS - 1` permits are added to the semaphore. When `RwLockWriteGuard::drop` gets invoked however another `MAX_READS` permits are added. This results in releasing more permits that were actually aquired when downgrading a write to a read lock. This is why we need to call `mem::forget` on the `RwLockWriteGuard` in order to avoid invoking the destructor. Fixes: #2941
2020-10-21sync: revert Clone impl for broadcast::Receiver (#3020)Carl Lerche
The `Receiver` handle maintains a position in the broadcast channel for itself. Cloning implies copying the state of the value. Intuitively, cloning a `broadcast::Receiver` would return a new receiver with an identical position. However, the current implementation returns a new `Receiver` positioned at the tail of the channel. This behavior subtlety is why `new_subscriber()` is used to create `Receiver` handles. An alternate API should consider the position issue. Refs: #2933
2020-10-21sync: add is_closed method to watch sender (#2991)Nikolai Kuklin
2020-10-21sync: remove extra clone in Semaphore::[try_]acquire_owned (#3015)Philip Kannegaard Hayes
2020-10-19sync: implement Clone for broadcast::Receiver (#2933)Zephyr Shannon
2020-10-12rt: simplify rt-* features (#2949)Taiki Endo
tokio: merge rt-core and rt-util as rt rename rt-threaded to rt-multi-thread tokio-util: rename rt-core to rt Closes #2942
2020-10-12rt: Remove `threaded_scheduler()` and `basic_scheduler()` (#2876)Lucio Franco
Co-authored-by: Alice Ryhl <alice@ryhl.io> Co-authored-by: Carl Lerche <me@carllerche.com>
2020-10-12sync: change chan `closed(&mut self)` to `closed(&self)` (#2939)Zahari Dichev
2020-10-09sync: move broadcast error types into broadcast::error module (#2937)Taiki Endo
Refs: #2928
2020-10-09fs: future proof `File` (#2930)Carl Lerche
Changes inherent methods to take `&self` instead of `&mut self`. This brings the API in line with `std`. This patch is implemented by using a `tokio::sync::Mutex` to guard the internal `File` state. This is not an ideal implementation strategy doesn't make a big impact compared to having to dispatch operations to a background thread followed by a blocking syscall. In the future, the implementation can be improved as we explore async file-system APIs provided by the operating-system (iocp / io_uring). Closes #2927
2020-10-08time: rename `Delay` future to `Sleep` (#2932)Juan Alvarez
2020-10-08chore: Fix clippy lints (#2931)bdonlan
Closes: #2929 Co-authored-by: Bryan Donlan <bdonlan@amazon.com>
2020-10-05sync: broadcast channel API tweaks (#2898)Alice Ryhl
Removes deprecated APIs and makes some small breaking changes.
2020-10-01chore: make #[doc(hidden)] apis private (#2901)Alice Ryhl
2020-10-02Fix new clippy warning (#2899)Alice Ryhl
2020-10-01time: introduce `sleep` and `sleep_until` functions (#2826)Juan Alvarez
2020-09-28sync: Add `is_closed` method to mpsc senders (#2726)Mikail Bagishov
Co-authored-by: Alice Ryhl <alice@ryhl.io>
2020-09-25sync: add `mpsc::Sender::closed` future (#2840)Zahari Dichev
Adding closed future, makes it possible to select over closed and some other work, so that the task is woken when the channel is closed and can proactively cancel itself. Added a mpsc::Sender::closed future that will become ready when the receiver is closed.
2020-09-25chore: handle std `Mutex` poisoning in a shim (#2872)Zahari Dichev
As tokio does not rely on poisoning, we can avoid always unwrapping when locking by handling the `PoisonError` in the Mutex shim. Signed-off-by: Zahari Dichev <zaharidichev@gmail.com>
2020-09-24sync: support mpsc send with `&self` (#2861)Carl Lerche
Updates the mpsc channel to use the intrusive waker based sempahore. This enables using `Sender` with `&self`. Instead of using `Sender::poll_ready` to ensure capacity and updating the `Sender` state, `async fn Sender::reserve()` is added. This function returns a `Permit` value representing the reserved capacity. Fixes: #2637 Refs: #2718 (intrusive waiters)
2020-09-24process: do not publicly turn on `signal` when enabled (#2871)Ivan Petkov
This change will still internally compile any `signal` resources required when `process` is enabled on unix systems, but it will not publicly turn on the cargo feature
2020-09-24rt: Allow concurrent `Shell:block_on` calls (#2868)Lucio Franco
2020-09-23io: use intrusive wait list for I/O driver (#2828)Sean McArthur
This refactors I/O registration in a few ways: - Cleans up the cached readiness in `PollEvented`. This cache used to be helpful when readiness was a linked list of `*mut Node`s in `Registration`. Previous refactors have turned `Registration` into just an `AtomicUsize` holding the current readiness, so the cache is just extra work and complexity. Gone. - Polling the `Registration` for readiness now gives a `ReadyEvent`, which includes the driver tick. This event must be passed back into `clear_readiness`, so that the readiness is only cleared from `Registration` if the tick hasn't changed. Previously, it was possible to clear the readiness even though another thread had *just* polled the driver and found the socket ready again. - Registration now also contains an `async fn readiness`, which stores wakers in an instrusive linked list. This allows an unbounded number of tasks to register for readiness (previously, only 1 per direction (read and write)). By using the intrusive linked list, there is no concern of leaking the storage of the wakers, since they are stored inside the `async fn` and released when the future is dropped. - Registration retains a `poll_readiness(Direction)` method, to support `AsyncRead` and `AsyncWrite`. They aren't able to use `async fn`s, and so there are 2 reserved slots for those methods. - IO types where it makes sense to have multiple tasks waiting on them now take advantage of this new `async fn readiness`, such as `UdpSocket` and `UnixDatagram`. Additionally, this makes the `io-driver` "feature" internal-only (no longer documented, not part of public API), and adds a second internal-only feature, `io-readiness`, to group together linked list part of registration that is only used by some of the IO types. After a bit of discussion, changing stream-based transports (like `TcpStream`) to have `async fn read(&self)` is punted, since that is likely too easy of a footgun to activate. Refs: #2779, #2728
2020-09-23rt: Allow concurrent `block_on`'s with basic_scheduler (#2804)Lucio Franco
2020-09-23sync: add `get_mut()` for `Mutex,RwLock` (#2856)Daniel Henry-Mantilla
2020-09-22sync: Remove readiness assertion in `watch::Receiver::changed() (#2839)Zahari Dichev
*In `watch::Receiver::changed` `Notified` was polled for the first time to ensure the waiter is registered while assuming that the first poll will always return `Pending`. It is the case however that another instance of `Notified` is dropped without receiving its notification, this "orphaned" notification can be used to satisfy another waiter without even registering it. This commit accounts for that scenario.
2020-09-21sync: fix missing notification during mpsc close (#2854)Carl Lerche
When the mpsc channel receiver closes the channel, receiving should return `None` once all in-progress sends have completed. When a sender reserves capacity, this prevents the receiver from fully shutting down. Previously, when the sender, after reserving capacity, dropped without sending a message, the receiver was not notified. This results in blocking the shutdown process until all sender handles drop. This patch adds a receiver notification when the channel is both closed and all outstanding sends have completed.
2020-09-17sync: fix some doc typos (#2838)Nylonicious
Fixes #2781.
2020-09-13doc: fix some links (#2834)Alice Ryhl
2020-09-12sync: add const constructors to RwLock, Notify, and Semaphore (#2833)Frank Steffahn
* Add const constructors to `RwLock`, `Notify`, and `Semaphore`. Referring to the types in `tokio::sync`. Also add `const` to `new` for the remaining atomic integers in `src/loom` and `UnsafeCell`. Builds upon previous work in #2790 Closes #2756
2020-09-12sync: add const-constructors for some sync primitives (#2790)mental
Co-authored-by: Mikail Bagishov <bagishov.mikail@yandex.ru> Co-authored-by: Eliza Weisman <eliza@buoyant.io> Co-authored-by: Alice Ryhl <alice@ryhl.io>
2020-09-11sync: tweak `watch` API (#2814)Carl Lerche
Decouples getting the latest `watch` value from receiving the change notification. The `Receiver` async method becomes `Receiver::changed()`. The latest value is obtained from `Receiver::borrow()`. The implementation is updated to use `Notify`. This requires adding `Notify::notify_waiters`. This method is generally useful but is kept private for now.
2020-09-11sync: write guard to read guard downgrading for sync::RwLock (#2733)Max Heller
2020-09-11docs: more doc fixes (#2831)Zephyr Shannon
Previous docs look like they were based on the docs for `insert_at`. Changed names of variables referred to and the explanation of when the value will be returned and under what condition it will be immediately available to make sense for a Duration argument instead of an Instant.
2020-09-09sync: document mpsc::bounded minimum buffer size (#2808)Zephyr Shannon
2020-09-08sync: remove rt-core from blocking_{send,recv} (#2825)Blas Rodriguez Irizar
2020-09-07sync: rename `Notify::notify()` -> `notify_one()` (#2822)Juan Alvarez
Closes: #2813
2020-09-02util: add `const fn` support for internal `LinkedList`. (#2805)mental
2020-09-01sync: watch channel breaking changes (#2806)Blas Rodriguez Irizar
Fixes: #2172
2020-08-26sync: add blocking_recv and blocking_send in mpsc (#2684)xd009642
Fixes: #2629
2020-08-26sync: implement map methods of parking_lot fame (#2445)John-John Tedro
Generally, this mimics the way `MappedRwLock*Guard`s are implemented in `parking_lot`. By storing a raw pointer in the guards themselves referencing the mapped data and maintaining type invariants through `PhantomData`. I didn't try to think too much about this, so if someone has objections I'd love to hear them. I've also dropped the internal use of `ReleasingPermit`, since it made the guards unecessarily large. The number of permits that need to be released are already known by the guards themselves, and is instead governed directly in the relevant `Drop` impls. This has the benefit of making the guards as small as possible, for the non-mapped variants this means a single reference is enough. `fmt::Debug` impls have been adjusted to behave exactly like the delegating impls in `parking_lot`. `fmt::Display` impls have been added for all guard types which behave the same. This does change the format of debug impls, for which I'm not sure if we provide any guarantees.
2020-08-26sync: fix typo in Notify documentation (#2794)James Mills