This commit is contained in:
noah
2026-05-29 16:25:29 -05:00
parent 70402f86a5
commit 398e91fc77
4 changed files with 17 additions and 62 deletions
@@ -4,8 +4,10 @@ use crate::runtime::driver::{self, Driver};
use crate::runtime::scheduler::{self, Defer, Inject};
use crate::runtime::task::{self, JoinHandle, OwnedTasks, Schedule, SpawnLocation, Task};
use crate::runtime::{
blocking, context, Config, MetricsBatch, SchedulerMetrics, TaskHooks, TaskMeta, WorkerMetrics,
blocking, context, Config, MetricsBatch, SchedulerMetrics, TaskHooks, WorkerMetrics,
};
#[cfg(tokio_unstable)]
use crate::runtime::TaskMeta;
use crate::sync::notify::Notify;
use crate::util::atomic_cell::AtomicCell;
use crate::util::{waker_ref, RngSeedGenerator, Wake, WakerRef};
@@ -5,8 +5,10 @@ use crate::runtime::task::{Notified, Task};
use crate::runtime::{
blocking, driver,
task::{self, JoinHandle, SpawnLocation},
TaskHooks, TaskMeta, TimerFlavor,
TaskHooks, TimerFlavor,
};
#[cfg(tokio_unstable)]
use crate::runtime::TaskMeta;
use crate::util::RngSeedGenerator;
use std::fmt;
-59
View File
@@ -84,34 +84,6 @@ impl<S: 'static> OwnedTasks<S> {
}
}
/// Binds the provided task to this `OwnedTasks` instance. This fails if the
/// `OwnedTasks` has been closed.
#[cfg_attr(tokio_unstable, allow(dead_code))]
pub(crate) fn bind<T>(
&self,
task: T,
scheduler: S,
id: super::Id,
spawned_at: SpawnLocation,
#[cfg(tokio_unstable)] user_data: Option<crate::runtime::TaskData>,
) -> (JoinHandle<T::Output>, Option<Notified<S>>)
where
S: Schedule,
T: Future + Send + 'static,
T::Output: Send + 'static,
{
let (task, notified, join) = super::new_task(
task,
scheduler,
id,
spawned_at,
#[cfg(tokio_unstable)]
user_data,
);
let notified = unsafe { self.bind_inner(task, notified) };
(join, notified)
}
pub(crate) fn bind_with_spawn_hook<T>(
&self,
task: T,
@@ -139,37 +111,6 @@ impl<S: 'static> OwnedTasks<S> {
(join, notified)
}
/// Bind a task that isn't safe to transfer across thread boundaries.
///
/// # Safety
///
/// Only use this in `LocalRuntime` where the task cannot move
#[cfg_attr(tokio_unstable, allow(dead_code))]
pub(crate) unsafe fn bind_local<T>(
&self,
task: T,
scheduler: S,
id: super::Id,
spawned_at: SpawnLocation,
#[cfg(tokio_unstable)] user_data: Option<crate::runtime::TaskData>,
) -> (JoinHandle<T::Output>, Option<Notified<S>>)
where
S: Schedule,
T: Future + 'static,
T::Output: 'static,
{
let (task, notified, join) = super::new_task(
task,
scheduler,
id,
spawned_at,
#[cfg(tokio_unstable)]
user_data,
);
let notified = unsafe { self.bind_inner(task, notified) };
(join, notified)
}
/// # Safety
///
/// Only use this in `LocalRuntime` where the task cannot move.
+11 -1
View File
@@ -2,6 +2,7 @@ use crate::runtime::task::{
self, unowned, Id, JoinHandle, OwnedTasks, Schedule, SpawnLocation, Task,
};
use crate::runtime::tests::NoopSchedule;
use crate::runtime::TaskHooks;
use std::collections::VecDeque;
use std::future::Future;
@@ -421,13 +422,22 @@ impl Runtime {
T: 'static + Send + Future,
T::Output: 'static + Send,
{
let (handle, notified) = self.0.owned.bind(
let task_hooks = TaskHooks {
task_spawn_callback: None,
task_terminate_callback: None,
#[cfg(tokio_unstable)]
before_poll_callback: None,
#[cfg(tokio_unstable)]
after_poll_callback: None,
};
let (handle, notified) = self.0.owned.bind_with_spawn_hook(
future,
self.clone(),
Id::next(),
SpawnLocation::capture(),
#[cfg(tokio_unstable)]
None,
&task_hooks,
);
if let Some(notified) = notified {