aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorHaibo Huang <hhb@google.com>2020-11-02 18:47:23 -0800
committerHaibo Huang <hhb@google.com>2020-11-02 18:47:23 -0800
commitbdf61e668e0593f8bcd0d30c512e7d5dbd09e38e (patch)
tree8847c6faf37c650915f060a07b3a0594cbff4b95 /src/runtime
parent4e8243bbb2f7f2747e80aafd270af79afebd0f38 (diff)
downloadtokio-bdf61e668e0593f8bcd0d30c512e7d5dbd09e38e.tar.gz
Upgrade rust/crates/tokio to 0.3.3
Test: make Change-Id: I8fdff1bab68b03bc1fe8179d07e79bd6ece31027
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/blocking/pool.rs2
-rw-r--r--src/runtime/blocking/task.rs3
-rw-r--r--src/runtime/handle.rs16
-rw-r--r--src/runtime/mod.rs7
4 files changed, 25 insertions, 3 deletions
diff --git a/src/runtime/blocking/pool.rs b/src/runtime/blocking/pool.rs
index 2967a10..6b9fb1b 100644
--- a/src/runtime/blocking/pool.rs
+++ b/src/runtime/blocking/pool.rs
@@ -70,6 +70,7 @@ const KEEP_ALIVE: Duration = Duration::from_secs(10);
pub(crate) fn spawn_blocking<F, R>(func: F) -> JoinHandle<R>
where
F: FnOnce() -> R + Send + 'static,
+ R: Send + 'static,
{
let rt = context::current().expect("not currently running on the Tokio runtime.");
rt.spawn_blocking(func)
@@ -79,6 +80,7 @@ where
pub(crate) fn try_spawn_blocking<F, R>(func: F) -> Result<(), ()>
where
F: FnOnce() -> R + Send + 'static,
+ R: Send + 'static,
{
let rt = context::current().expect("not currently running on the Tokio runtime.");
diff --git a/src/runtime/blocking/task.rs b/src/runtime/blocking/task.rs
index a521af4..ee2d8d6 100644
--- a/src/runtime/blocking/task.rs
+++ b/src/runtime/blocking/task.rs
@@ -19,7 +19,8 @@ impl<T> Unpin for BlockingTask<T> {}
impl<T, R> Future for BlockingTask<T>
where
- T: FnOnce() -> R,
+ T: FnOnce() -> R + Send + 'static,
+ R: Send + 'static,
{
type Output = R;
diff --git a/src/runtime/handle.rs b/src/runtime/handle.rs
index b1e8d8f..72b9c06 100644
--- a/src/runtime/handle.rs
+++ b/src/runtime/handle.rs
@@ -39,13 +39,27 @@ impl Handle {
// context::enter(self.clone(), f)
// }
- /// Run the provided function on an executor dedicated to blocking operations.
+ /// Run the provided function on an executor dedicated to blocking
+ /// operations.
+ #[cfg_attr(tokio_track_caller, track_caller)]
pub(crate) fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
where
F: FnOnce() -> R + Send + 'static,
+ R: Send + 'static,
{
#[cfg(feature = "tracing")]
let func = {
+ #[cfg(tokio_track_caller)]
+ let location = std::panic::Location::caller();
+ #[cfg(tokio_track_caller)]
+ let span = tracing::trace_span!(
+ target: "tokio::task",
+ "task",
+ kind = %"blocking",
+ function = %std::any::type_name::<F>(),
+ spawn.location = %format_args!("{}:{}:{}", location.file(), location.line(), location.column()),
+ );
+ #[cfg(not(tokio_track_caller))]
let span = tracing::trace_span!(
target: "tokio::task",
"task",
diff --git a/src/runtime/mod.rs b/src/runtime/mod.rs
index be4aa38..f85344d 100644
--- a/src/runtime/mod.rs
+++ b/src/runtime/mod.rs
@@ -357,11 +357,14 @@ cfg_rt! {
/// });
/// # }
/// ```
+ #[cfg_attr(tokio_track_caller, track_caller)]
pub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output>
where
F: Future + Send + 'static,
F::Output: Send + 'static,
{
+ #[cfg(feature = "tracing")]
+ let future = crate::util::trace::task(future, "task");
match &self.kind {
#[cfg(feature = "rt-multi-thread")]
Kind::ThreadPool(exec) => exec.spawn(future),
@@ -385,9 +388,11 @@ cfg_rt! {
/// println!("now running on a worker thread");
/// });
/// # }
+ #[cfg_attr(tokio_track_caller, track_caller)]
pub fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
where
F: FnOnce() -> R + Send + 'static,
+ R: Send + 'static,
{
self.handle.spawn_blocking(func)
}
@@ -415,7 +420,7 @@ cfg_rt! {
///
/// # Panics
///
- /// This function panics if the provided future panics, or if not called within an
+ /// This function panics if the provided future panics, or if called within an
/// asynchronous execution context.
///
/// # Examples