summaryrefslogtreecommitdiffstats
path: root/tokio/src/lib.rs
AgeCommit message (Collapse)Author
2020-12-11net: remove empty udp module (#3260)Evan Cameron
2020-12-09chore: prepare for Tokio 1.0 work (#3238)Carl Lerche
2020-11-30chore: prepare v0.3.5 release (#3201)Carl Lerche
2020-11-18chore: prepare v0.3.4 release (#3152)Carl Lerche
2020-11-02chore: prepare v0.3.3 release (#3090)Carl Lerche
2020-10-27chore: prepare v0.3.2 release (#3059)Carl Lerche
2020-10-22io: Add AsyncFd, fix io::driver shutdown (#2903)bdonlan
* io: Add AsyncFd This adds AsyncFd, a unix-only structure to allow for read/writability states to be monitored for arbitrary file descriptors. Issue: #2728 * driver: fix shutdown notification unreliability Previously, there was a race window in which an IO driver shutting down could fail to notify ScheduledIo instances of this state; in particular, notification of outstanding ScheduledIo registrations was driven by `Driver::drop`, but registrations bypass `Driver` and go directly to a `Weak<Inner>`. The `Driver` holds the `Arc<Inner>` keeping `Inner` alive, but it's possible that a new handle could be registered (or a new readiness future created for an existing handle) after the `Driver::drop` handler runs and prior to `Inner` being dropped. This change fixes this in two parts: First, notification of outstanding ScheduledIo handles is pushed down into the drop method of `Inner` instead, and, second, we add state to ScheduledIo to ensure that we remember that the IO driver we're bound to has shut down after the initial shutdown notification, so that subsequent readiness future registrations can immediately return (instead of potentially blocking indefinitely). Fixes: #2924
2020-10-21chore: prepare v0.3.1 release (#3021)Carl Lerche
2020-10-16doc: update version to 0.3 in module documentation (#2974)messense
2020-10-12meta: combine `net` and `dns`, use `parking_lot` (#2951)Carl Lerche
This combines the `dns` and `net` feature flags. Previously, `dns` was included as part of `net`. Given that is is rare that one would want `dns` without `net`, DNS is now entirely gated w/ `net`. The `parking_lot` feature is included as part of `full`. Some misc docs are tweaked to reflect feature flag changes.
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-13net: merge tcp, udp, uds features to net feature (#2943)Taiki Endo
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-12chore: remove use of doc_alias feature (#2944)Taiki Endo
2020-10-08time: rename `Delay` future to `Sleep` (#2932)Juan Alvarez
2020-10-08net: use &self with TcpListener::accept (#2919)Carl Lerche
Uses the infrastructure added by #2828 to enable switching `TcpListener::accept` to use `&self`. This also switches `poll_accept` to use `&self`. While doing introduces a hazard, `poll_*` style functions are considered low-level. Most users will use the `async fn` variants which are more misuse-resistant. TcpListener::incoming() is temporarily removed as it has the same problem as `TcpSocket::by_ref()` and will be implemented later.
2020-10-01time: introduce `sleep` and `sleep_until` functions (#2826)Juan Alvarez
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-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-05runtime: improve runtime vs #[tokio::main] doc (#2820)Igor Aleksanov
2020-08-27Docs delay queue (#2793)Blas Rodriguez Irizar
2020-08-07chore: prepare for v0.3 breaking changes (#2747)Carl Lerche
Bug fixes will be applied to the v0.2.x branch.
2020-07-22doc: fix links to new website (#2674)Alice Ryhl
2020-07-21chore: prepare to release 0.2.22 (#2672)Eliza Weisman
# 0.2.22 (July 2!, 2020) ### Fixes - docs: misc improvements (#2572, #2658, #2663, #2656, #2647, #2630, #2487, #2621, #2624, #2600, #2623, #2622, #2577, #2569, #2589, #2575, #2540, #2564, #2567, #2520, #2521, #2493) - rt: allow calls to `block_on` inside calls to `block_in_place` that are themselves inside `block_on` (#2645) - net: fix non-portable behavior when dropping `TcpStream` `OwnedWriteHalf` (#2597) - io: improve stack usage by allocating large buffers on directly on the heap (#2634) - io: fix unsound pin projection in `AsyncReadExt::read_buf` and `AsyncWriteExt::write_buf` (#2612) - io: fix unnecessary zeroing for `AsyncRead` implementors (#2525) - io: Fix `BufReader` not correctly forwarding `poll_write_buf` (#2654) - io: fix panic in `AsyncReadExt::read_line` (#2541) ### Changes - coop: returning `Poll::Pending` no longer decrements the task budget (#2549) ### Added - io: little-endian variants of `AsyncReadExt` and `AsyncWriteExt` methods (#1915) - task: add [`tracing`] instrumentation to spawned tasks (#2655) - sync: allow unsized types in `Mutex` and `RwLock` (via `default` constructors) (#2615) - net: add `ToSocketAddrs` implementation for `&[SocketAddr]` (#2604) - fs: add `OpenOptionsExt` for `OpenOptions` (#2515) - fs: add `DirBuilder` (#2524) [`tracing`]: https://crates.io/crates/tracing Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-06-10doc: add sleep alias to delay_for (#2589)Alice Ryhl
2020-05-16sync: document maximum number of permits (#2539)ZSL
2020-05-13chore: prepare v0.2.21 release (#2530)Carl Lerche
2020-04-28chore: prepare v0.2.20 release. (#2458)Carl Lerche
2020-04-24chore: prepare v0.2.19 release (#2441)Carl Lerche
2020-04-18doc: mention CPU-bound code lib.rs (#2414)Alice Ryhl
2020-04-12chore: prepare to release 0.2.18 (#2399)Alice Ryhl
2020-04-09chore: prepare to release 0.2.17 (#2392)Eliza Weisman
# 0.2.17 (April 9, 2020) ### Fixes - rt: bug in work-stealing queue (#2387) ### Changes - rt: threadpool uses logical CPU count instead of physical by default (#2391) Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-04-03sync: ensure Mutex, RwLock, and Semaphore futures are Send + Sync (#2375)Eliza Weisman
Previously, the `Mutex::lock`, `RwLock::{read, write}`, and `Semaphore::acquire` futures in `tokio::sync` implemented `Send + Sync` automatically. This was by virtue of being implemented using a `poll_fn` that only closed over `Send + Sync` types. However, this broke in PR #2325, which rewrote those types using the new `batch_semaphore`. Now, they await an `Acquire` future, which contains a `Waiter`, which internally contains an `UnsafeCell`, and thus does not implement `Sync`. Since removing previously implemented traits breaks existing code, this inadvertantly caused a breaking change. There were tests ensuring that the `Mutex`, `RwLock`, and `Semaphore` types themselves were `Send + Sync`, but no tests that the _futures they return_ implemented those traits. I've fixed this by adding an explicit impl of `Sync` for the `batch_semaphore::Acquire` future. Since the `Waiter` type held by this struct is only accessed when borrowed mutably, it is safe for it to implement `Sync`. Additionally, I've added to the bounds checks for the effected `tokio::sync` types to ensure that returned futures continue to implement `Send + Sync` in the future.
2020-04-02chore: Prepare `0.2.15` release (#2365)Lucio Franco
Signed-off-by: Lucio Franco <luciofranco14@gmail.com>
2020-04-01chore: prepare tokio v0.2.14 release (#2356)Carl Lerche
2020-03-16Add cooperative task yielding (#2160)Jon Gjengset
A single call to `poll` on a top-level task may potentially do a lot of work before it returns `Poll::Pending`. If a task runs for a long period of time without yielding back to the executor, it can starve other tasks waiting on that executor to execute them, or drive underlying resources. See for example rust-lang/futures-rs#2047, rust-lang/futures-rs#1957, and rust-lang/futures-rs#869. Since Rust does not have a runtime, it is difficult to forcibly preempt a long-running task. Consider a future like this one: ```rust use tokio::stream::StreamExt; async fn drop_all<I: Stream>(input: I) { while let Some(_) = input.next().await {} } ``` It may look harmless, but consider what happens under heavy load if the input stream is _always_ ready. If we spawn `drop_all`, the task will never yield, and will starve other tasks and resources on the same executor. This patch adds a `coop` module that provides an opt-in mechanism for futures to cooperate with the executor to avoid starvation. This alleviates the problem above: ``` use tokio::stream::StreamExt; async fn drop_all<I: Stream>(input: I) { while let Some(_) = input.next().await { tokio::coop::proceed().await; } } ``` The call to [`proceed`] will coordinate with the executor to make sure that every so often control is yielded back to the executor so it can run other tasks. The implementation uses a thread-local counter that simply counts how many "cooperation points" we have passed since the task was first polled. Once the "budget" has been spent, any subsequent points will return `Poll::Pending`, eventually making the top-level task yield. When it finally does yield, the executor resets the budget before running the next task. The budget per task poll is currently hard-coded to 128. Eventually, we may want to make it dynamic as more cooperation points are added. The number 128 was chosen more or less arbitrarily to balance the cost of yielding unnecessarily against the time an executor may be "held up". At the moment, all the tokio leaf futures ("resources") call into coop, but external futures have no way of doing so. We probably want to continue limiting coop points to leaf futures in the future, but may want to also enable third-party leaf futures to cooperate to benefit the ecosystem as a whole. This is reflected in the methods marked as `pub` in `mod coop` (even though the module is only `pub(crate)`). We will likely also eventually want to expose `coop::limit`, which enables sub-executors and manual `impl Future` blocks to avoid one sub-task spending all of their poll budget. Benchmarks (see tokio-rs/tokio#2160) suggest that the overhead of `coop` is marginal.
2020-03-05rt: cleanup and simplify scheduler (scheduler v2.5) (#2273)Carl Lerche
A refactor of the scheduler internals focusing on simplifying and reducing unsafety. There are no fundamental logic changes. * The state transitions of the core task component are refined and reduced. * `basic_scheduler` has most unsafety removed. * `local_set` has most unsafety removed. * `threaded_scheduler` limits most unsafety to its queue implementation.
2020-02-28chore: prepare v0.2.13 release (#2282)Carl Lerche
Includes a quick bug fix
2020-02-27chore: prepare v0.2.12 release (#2278)Carl Lerche
Also includes `tokio-macros` v0.2.5.
2020-02-26docs: macros doc(cfg) workarounds (#2225)David Kellum
This is a workaround for the fact that the doc(cfg) from outer cfg_* macros doesn't get applied correctly. Its included in the rt-threaded branch only, which is what is used for doc.rs via all-features.
2020-01-27chore: prepare v0.2.11 release (#2179)Carl Lerche
Also bumps: - tokio-macros: v0.2.4
2020-01-24rt: add feature flag for using `parking_lot` internally (#2164)David Kellum
`parking_lot` provides synchronization primitives that tend to be more efficient than the ones in `std`. However, depending on `parking_lot` pulls in a number of dependencies resulting in additional compilation time. Adding *optional* support for `parking_lot` allows the end user to opt-in when the trade offs make sense for their case.
2020-01-22Provide `select!` macro (#2152)Carl Lerche
Provides a `select!` macro for concurrently waiting on multiple async expressions. The macro has similar goals and syntax as the one provided by the `futures` crate, but differs significantly in implementation. First, this implementation does not require special traits to be implemented on futures or streams (i.e., no `FuseFuture`). A design goal is to be able to pass a "plain" async fn result into the select! macro. Even without `FuseFuture`, this `select!` implementation is able to handle all cases the `futures::select!` macro can handle. It does this by supporting pre-poll conditions on branches and result pattern matching. For pre-conditions, each branch is able to include a condition that disables the branch if it evaluates to false. This allows the user to guard futures that have already been polled, preventing double polling. Pattern matching can be used to disable streams that complete. A second big difference is the macro is implemented almost entirely as a declarative macro. The biggest advantage to using this strategy is that the user will not need to alter the rustc recursion limit except in the most extreme cases. The resulting future also tends to be smaller in many cases.
2020-01-22docs: fix link to website (#2103)Przemysław Bitkowski
replace website link, because previous one was broken
2020-01-21chore: prepare v0.2.10 release (#2148)Carl Lerche
2020-01-21macros: fix `#[tokio::main]` without rt-core (#2139)Carl Lerche
The Tokio runtime provides a "shell" runtime when `rt-core` is not available. This shell runtime is enough to support `#[tokio::main`] and `#[tokio::test]. A previous change disabled these two attr macros when `rt-core` was not selected. This patch fixes this by re-enabling the `main` and `test` attr macros without `rt-core` and adds some integration tests to prevent future regressions.
2020-01-14chore: clippy fixes (#2110)Artem Vorotnikov
2020-01-09chore: prepare v0.2.9 release (#2084)Carl Lerche
2020-01-09docs: document feature flags (#2081)Lucio Franco
2020-01-07macros: fix breaking changes (#2069)Carl Lerche
Brings back old macro implementations and updates the version of tokio-macros that tokio depends on. Prepares a new release.