Commit Graph
2061 Commits
Author SHA1 Message Date
Sean McArthur dfdfd61372 Fix readiness future eagerly consuming entire socket readiness (#2887)
In the `readiness` future, before inserting a waiter into the list, the current socket readiness is eagerly checked. However, it would return as a `ReadyEvent` the entire socket readiness, instead of just the interest desired from `readiness(interest)`. This would result in the later call to `clear_readiness(event)` removing all of it.

Closes #2886
2020-09-25 16:34:40 -07:00
Zahari Dichev 55d932a21f sync: add mpsc::Sender::closed future (#2840)
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-25 08:40:31 -07:00
Zahari Dichev 444660664b chore: handle std Mutex poisoning in a shim (#2872)
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 <[email protected]>
2020-09-25 08:38:13 -07:00
Carl Lerche cf025ba45f sync: support mpsc send with &self (#2861)
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-24 17:26:38 -07:00
Carl Lerche 4186b0aa38 io: remove poll_{read,write}_buf from traits (#2882)
These functions have object safety issues. It also has been decided to
avoid vectored operations on the I/O traits. A later PR will bring back
vectored operations on specific types that support them.

Refs: #2879, #2716
2020-09-24 17:26:03 -07:00
bdonlanandBryan Donlan 760ae89401 chore: Use IoSlice's Copy impl to clean up some repetitive code (#2875)
As we go into 0.3 we no longer need to support older versions of Rust where
IoSlice did not implement Copy and Clone, so we can more easily initialize the
IoSlice array in net::tcp::stream.

Co-authored-by: Bryan Donlan <[email protected]>
2020-09-24 14:50:10 -07:00
Ivan Petkov 56acde069f chore: remove internal io-driver cargo feature (#2881) 2020-09-24 21:36:42 +00:00
Ivan Petkov ffa5bdb22d chore: remove internal io-readiness cargo feature (#2878) 2020-09-24 20:14:39 +00:00
Ivan Petkov a1d0681cd2 process: do not publicly turn on signal when enabled (#2871)
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-24 10:51:46 -07:00
Lucio Franco 4dfbdbff7e rt: Allow concurrent Shell:block_on calls (#2868) 2020-09-24 13:31:49 -04:00
Taiki Endo c29f13b7a5 docs: use #[doc(no_inline)] on re-exports (#2874) 2020-09-24 22:59:47 +09:00
Sean McArthur a0557840eb io: use intrusive wait list for I/O driver (#2828)
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-23 13:02:15 -07:00
Lucio Franco f25f12d576 rt: Allow concurrent block_on's with basic_scheduler (#2804) 2020-09-23 14:35:10 -04:00
Daniel Henry-Mantilla 0f70530ee7 sync: add get_mut() for Mutex,RwLock (#2856) 2020-09-23 10:30:43 -07:00
kalcutter 3114d9e826 net: change UnixListener::poll_accept to public (#2845) 2020-09-23 16:21:18 +02:00
Alice Ryhl 5467f0a573 io: move #[cfg(not(loom))] to fix warning (#2864) 2020-09-23 11:04:52 +02:00
Mikail Bagishov 555b74c7cd io: fix stdout and stderr buffering on windows (#2734) 2020-09-23 08:16:05 +02:00
Ivan Petkov 7ae5b7bd4f signal: move driver to runtime thread (#2835)
Refactors the signal infrastructure to move the driver to the runtime
thread. This follows the model put forth by the I/O driver and time
driver.
2020-09-22 15:40:44 -07:00
Alice Ryhl e09b90ea32 macros: add #[allow(unused_mut)] to select! (#2858) 2020-09-23 05:56:45 +09:00
Taiki Endo cb8f2ceb2e chore: remove unused future/pending.rs (#2860) 2020-09-23 05:55:58 +09:00
Taiki Endo 6866b24ca1 ci: deny warnings on '--cfg tokio_unstable' tests (#2859) 2020-09-23 05:55:35 +09:00
Zahari Dichev e7091fde78 sync: Remove readiness assertion in `watch::Receiver::changed() (#2839)
*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-22 08:12:57 -07:00
Carl Lerche 2348f678e6 Merge remote-tracking branch 'origin/v0.2.x' into merge-v0.2 2020-09-21 14:35:38 -07:00
Carl Lerche 93f8cb8df2 sync: fix missing notification during mpsc close (#2854)
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-21 14:35:09 -07:00
Carl Lerche c0c7124a4b sync: fix missing notification during mpsc close (#2854)
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-21 14:29:22 -07:00
Alice RyhlandTaiki Endo 1ac10fa80a ci: update miri flags (#2851)
* ci: update miri flags

* Update 2020-09-20 to 2020-09-21

Co-authored-by: Taiki Endo <[email protected]>

Co-authored-by: Taiki Endo <[email protected]>
2020-09-21 18:57:33 +02:00
Alice RyhlandBlas Rodriguez Irizar 2b96b1773d ci: update nightly and fix all sorts of new failures (#2852)
* ci: update miri flags

* ci: fix doc warnings

* doc: fix some links

Cherry-pick of 18ed761 from #2834

* ci: cherry-pick 00a2849

From: #2793

* ci: cherry-pick 6b61212

From: #2793

Co-authored-by: Blas Rodriguez Irizar <[email protected]>
2020-09-21 18:57:27 +02:00
Taiki Endo ba8680d667 io: fix doc-cfg on AsyncSeekExt (#2846) 2020-09-19 20:40:37 +09:00
Taiki Endo 111894fef9 util: remove Slice wrapper (#2847) 2020-09-19 20:40:20 +09:00
Taiki Endo 68f7eff39e time: remove outdated todo comment (#2848) 2020-09-19 20:40:03 +09:00
NyloniciousandAlice Ryhl 207320dbbb process: fix some docs (#2843)
* fix docs for Command::status and output

Co-authored-by: Alice Ryhl <[email protected]>
2020-09-18 22:49:13 +00:00
Nylonicious 3fd043931e sync: fix some doc typos (#2838)
Fixes #2781.
2020-09-17 08:03:38 +02:00
Alice Ryhl 4c4699be00 doc: fix some links (#2834) 2020-09-13 15:50:40 +02:00
Frank Steffahn 8d2e3bc575 sync: add const constructors to RwLock, Notify, and Semaphore (#2833)
* 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-12 22:58:58 +02:00
20ef286553 sync: add const-constructors for some sync primitives (#2790)
Co-authored-by: Mikail Bagishov <[email protected]>
Co-authored-by: Eliza Weisman <[email protected]>
Co-authored-by: Alice Ryhl <[email protected]>
2020-09-12 11:55:03 +02:00
Carl Lerche 2bc9a48152 sync: tweak watch API (#2814)
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-11 15:14:45 -07:00
Max Heller c5a9ede157 sync: write guard to read guard downgrading for sync::RwLock (#2733) 2020-09-11 22:00:04 +02:00
Zephyr Shannon ce0af8f7a1 docs: more doc fixes (#2831)
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-11 12:44:33 -07:00
Zephyr Shannon be7462e50f sync: document mpsc::bounded minimum buffer size (#2808) 2020-09-09 22:28:28 +02:00
xd009642 1550dda5cf stream: module level docs for tokio::stream (#2786) 2020-09-09 09:08:23 +02:00
John-John Tedro cbb14a7bb9 sync: add JoinHandle::abort (#2474) 2020-09-08 20:52:57 -07:00
Blas Rodriguez Irizar a0a356152e sync: remove rt-core from blocking_{send,recv} (#2825) 2020-09-08 20:50:38 -07:00
Igor Aleksanov ea79c95c67 util: implement Either type (#2821) 2020-09-08 09:14:08 +02:00
37f405bd3b io: move StreamReader and ReaderStream into tokio_util (#2788)
Co-authored-by: Mikail Bagishov <[email protected]>
Co-authored-by: Eliza Weisman <[email protected]>
2020-09-08 09:12:32 +02:00
Ivan Petkov 7c254eca44 process: make Child::kill async (#2823)
* This changes the `Child::kill` to be an async method which awaits the
  child after sending a kill signal. This avoids leaving zombie
  processes on Unix platforms if the caller forgets to await the child
  after the kill completes
* A `start_kill` method was also added on `Child` which only sends the
  kill signal to the child process. This allows for kill signals to be
  sent even outside of async contexts.
2020-09-08 06:03:25 +00:00
Blas Rodriguez IrizarandEliza Weisman f4d6ed03d9 runtime: add custom keep_alive functionality (#2809)
Co-authored-by: Eliza Weisman <[email protected]>
Fixes: #2585
2020-09-07 21:32:34 +02:00
Juan Alvarez 38ec4845d1 sync: rename Notify::notify() -> notify_one() (#2822)
Closes: #2813
2020-09-07 20:56:15 +02:00
Ivan Petkov 842d5565bd process: add Child::{wait,try_wait} (#2796)
* add Child::try_wait to mirror the std API
* replace Future impl on Child with `.wait()` method to bring our
  APIs closer to those in std and it allow us to
  internally fuse the future so that repeated calls to `wait` result in
  the same value (similar to std) without forcing the caller to fuse the
  outer future
* Also change `Child::id` to return an Option result to avoid
  allowing the caller to accidentally use the pid on Unix systems after
  the child has been reaped
* Also remove deprecated Child methods
2020-09-07 03:30:40 +00:00
George Malayil Philip d74eabc7d7 runtime: mention on JoinHandle that the generic parameter is the return type (#2819) 2020-09-05 22:44:42 +02:00
Blas Rodriguez IrizarandMikail Bagishov 6260ed907b tokio: document missing timer panics (#2801)
Fixes: #2696
Co-authored-by: Mikail Bagishov <[email protected]>
2020-09-05 20:33:42 +02:00