summaryrefslogtreecommitdiffstats
path: root/tokio/src/macros
diff options
context:
space:
mode:
authorEliza Weisman <eliza@buoyant.io>2019-11-26 17:03:18 -0800
committerGitHub <noreply@github.com>2019-11-26 17:03:18 -0800
commit38e602f4d812c196d5dc0bc245e79ccad4e77cfd (patch)
tree2ca955e0737ce2b836d95f9329ad22befb1316a2 /tokio/src/macros
parent8e83a9f2c37fee3590d246b0420f688a0a9eea6b (diff)
task: add `LocalSet` API for running `!Send` futures (#1733)
## Motivation In earlier versions of `tokio`, the `current_thread::Runtime` type could be used to run `!Send` futures. However, PR #1716 merged the current-thread and threadpool runtimes into a single type, which can no longer run `!Send` futures. There is still a need in some cases to support futures that don't implement `Send`, and the `tokio-compat` crate requires this in order to provide APIs that existed in `tokio` 0.1. ## Solution This branch implements the API described by @carllerche in https://github.com/tokio-rs/tokio/pull/1716#issuecomment-549496309. It adds a new `LocalSet` type and `spawn_local` function to `tokio::task`. The `LocalSet` type is used to group together a set of tasks which must run on the same thread and don't implement `Send`. These are available when a new "rt-util" feature flag is enabled. Currently, the local task set is run by passing it a reference to a `Runtime` and a future to `block_on`. In the future, we may also want to investigate allowing spawned futures to construct their own local task sets, which would be executed on the worker that the future is executing on. In order to implement the new API, I've made some internal changes to the `task` module and `Schedule` trait to support scheduling both `Send` and `!Send` futures. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Diffstat (limited to 'tokio/src/macros')
-rw-r--r--tokio/src/macros/cfg.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/tokio/src/macros/cfg.rs b/tokio/src/macros/cfg.rs
index 959eed22..4aee3b7f 100644
--- a/tokio/src/macros/cfg.rs
+++ b/tokio/src/macros/cfg.rs
@@ -52,6 +52,21 @@ macro_rules! cfg_not_blocking_impl {
}
}
+/// Enable internal `AtomicWaker` impl
+macro_rules! cfg_atomic_waker_impl {
+ ($($item:item)*) => {
+ $(
+ #[cfg(any(
+ feature = "io-driver",
+ feature = "time",
+ all(feature = "rt-core", feature = "rt-util")
+ ))]
+ #[cfg(not(loom))]
+ $item
+ )*
+ }
+}
+
macro_rules! cfg_dns {
($($item:item)*) => {
$(
@@ -220,6 +235,16 @@ macro_rules! cfg_rt_threaded {
}
}
+macro_rules! cfg_rt_util {
+ ($($item:item)*) => {
+ $(
+ #[cfg(feature = "rt-util")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "rt-util")))]
+ $item
+ )*
+ }
+}
+
macro_rules! cfg_not_rt_threaded {
($($item:item)*) => {
$( #[cfg(not(feature = "rt-threaded"))] $item )*