Skip to content

rt: overhaul task hooks #7197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
on:
push:
branches: ["master", "tokio-*.x"]
branches: [ "master", "tokio-*.x" ]
pull_request:
branches: ["master", "tokio-*.x"]
branches: [ "master", "tokio-*.x" ]

name: CI

Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
- name: Install Rust ${{ env.rust_stable }}
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.rust_stable }}
toolchain: ${{ env.rust_stable }}
- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
- name: Install Rust ${{ env.rust_stable }}
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.rust_stable }}
toolchain: ${{ env.rust_stable }}
- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
Expand Down Expand Up @@ -169,7 +169,7 @@ jobs:
- name: Install Rust ${{ env.rust_nightly }}
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.rust_nightly }}
toolchain: ${{ env.rust_nightly }}
- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
Expand Down Expand Up @@ -197,7 +197,7 @@ jobs:
- name: Install Rust ${{ env.rust_stable }}
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.rust_stable }}
toolchain: ${{ env.rust_stable }}
- name: Install cargo-hack
uses: taiki-e/install-action@v2
with:
Expand Down Expand Up @@ -237,7 +237,7 @@ jobs:
- name: Install Rust ${{ env.rust_stable }}
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.rust_stable }}
toolchain: ${{ env.rust_stable }}

- name: Enable parking_lot send_guard feature
# Inserts the line "plsend = ["parking_lot/send_guard"]" right after [features]
Expand All @@ -256,7 +256,7 @@ jobs:
- name: Install Rust ${{ env.rust_stable }}
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.82
toolchain: 1.82

- name: Install Valgrind
uses: taiki-e/install-action@valgrind
Expand Down Expand Up @@ -295,7 +295,7 @@ jobs:
- name: Install Rust ${{ env.rust_stable }}
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.rust_stable }}
toolchain: ${{ env.rust_stable }}

- name: Install cargo-nextest
uses: taiki-e/install-action@v2
Expand Down Expand Up @@ -329,7 +329,7 @@ jobs:
- name: Install Rust ${{ env.rust_stable }}
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.rust_stable }}
toolchain: ${{ env.rust_stable }}

- name: Install cargo-nextest
uses: taiki-e/install-action@v2
Expand Down Expand Up @@ -363,7 +363,7 @@ jobs:
- name: Install Rust ${{ env.rust_stable }}
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.rust_stable }}
toolchain: ${{ env.rust_stable }}
- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
Expand Down Expand Up @@ -842,10 +842,10 @@ jobs:
toolchain: ${{ env.rust_stable }}
- uses: Swatinem/rust-cache@v2
- name: build --cfg loom
run: cargo test --no-run --lib --features full
run: cargo test --no-run --lib --release --features full
working-directory: tokio
env:
RUSTFLAGS: --cfg loom --cfg tokio_unstable -Dwarnings
RUSTFLAGS: --cfg loom --cfg tokio_unstable -Dwarnings -Cdebug-assertions

check-readme:
name: Check README
Expand Down
3 changes: 0 additions & 3 deletions tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,7 @@
//! - [`task::Builder`]
//! - Some methods on [`task::JoinSet`]
//! - [`runtime::RuntimeMetrics`]
//! - [`runtime::Builder::on_task_spawn`]
//! - [`runtime::Builder::on_task_terminate`]
//! - [`runtime::Builder::unhandled_panic`]
//! - [`runtime::TaskMeta`]
//!
//! This flag enables **unstable** features. The public API of these features
//! may break in 1.x releases. To enable these features, the `--cfg
Expand Down
5 changes: 5 additions & 0 deletions tokio/src/runtime/blocking/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,15 @@ impl Spawner {
F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
{
// let parent = with_c
let id = task::Id::next();
let fut =
blocking_task::<F, BlockingTask<F>>(BlockingTask::new(func), spawn_meta, id.as_u64());

#[cfg(tokio_unstable)]
let (task, handle) = task::unowned(fut, BlockingSchedule::new(rt), id, None);

#[cfg(not(tokio_unstable))]
let (task, handle) = task::unowned(fut, BlockingSchedule::new(rt), id);

let spawned = self.spawn_task(Task::new(task, is_mandatory), rt);
Expand Down
24 changes: 15 additions & 9 deletions tokio/src/runtime/blocking/schedule.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#[cfg(feature = "test-util")]
use crate::runtime::scheduler;
use crate::runtime::task::{self, Task, TaskHarnessScheduleHooks};
use crate::runtime::task::{self, Task};
use crate::runtime::Handle;
#[cfg(tokio_unstable)]
use crate::runtime::{OptionalTaskHooksFactory, OptionalTaskHooksFactoryRef};

/// `task::Schedule` implementation that does nothing (except some bookkeeping
/// in test-util builds). This is unique to the blocking scheduler as tasks
Expand All @@ -12,7 +14,8 @@ use crate::runtime::Handle;
pub(crate) struct BlockingSchedule {
#[cfg(feature = "test-util")]
handle: Handle,
hooks: TaskHarnessScheduleHooks,
#[cfg(tokio_unstable)]
hooks_factory: OptionalTaskHooksFactory,
}

impl BlockingSchedule {
Expand All @@ -31,9 +34,8 @@ impl BlockingSchedule {
BlockingSchedule {
#[cfg(feature = "test-util")]
handle: handle.clone(),
hooks: TaskHarnessScheduleHooks {
task_terminate_callback: handle.inner.hooks().task_terminate_callback.clone(),
},
#[cfg(tokio_unstable)]
hooks_factory: handle.inner.hooks_factory(),
}
}
}
Expand All @@ -58,9 +60,13 @@ impl task::Schedule for BlockingSchedule {
unreachable!();
}

fn hooks(&self) -> TaskHarnessScheduleHooks {
TaskHarnessScheduleHooks {
task_terminate_callback: self.hooks.task_terminate_callback.clone(),
}
#[cfg(tokio_unstable)]
fn hooks_factory(&self) -> OptionalTaskHooksFactory {
self.hooks_factory.clone()
}

#[cfg(tokio_unstable)]
fn hooks_factory_ref(&self) -> OptionalTaskHooksFactoryRef<'_> {
self.hooks_factory.as_ref().map(AsRef::as_ref)
}
}
Loading
Loading