-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
rt: switch io::handle refs with scheduler:Handle #5128
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,13 @@ impl Handle { | |
} | ||
} | ||
|
||
cfg_io_driver! { | ||
#[track_caller] | ||
pub(crate) fn io(&self) -> &crate::runtime::io::Handle { | ||
self.driver().io() | ||
} | ||
} | ||
|
||
cfg_time! { | ||
#[track_caller] | ||
pub(crate) fn time(&self) -> &crate::runtime::time::Handle { | ||
|
@@ -62,6 +69,11 @@ cfg_rt! { | |
use crate::util::RngSeedGenerator; | ||
|
||
impl Handle { | ||
#[track_caller] | ||
pub(crate) fn current() -> Handle { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving the Eventually, |
||
crate::runtime::context::current().inner | ||
} | ||
|
||
pub(crate) fn blocking_spawner(&self) -> &blocking::Spawner { | ||
match self { | ||
Handle::CurrentThread(h) => &h.blocking_spawner, | ||
|
@@ -156,3 +168,12 @@ cfg_rt! { | |
} | ||
} | ||
} | ||
|
||
cfg_not_rt! { | ||
impl Handle { | ||
#[track_caller] | ||
pub(crate) fn current() -> Handle { | ||
panic!("{}", crate::util::error::CONTEXT_MISSING_ERROR) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,76 +248,61 @@ cfg_not_trace! { | |
} | ||
|
||
impl Sleep { | ||
cfg_rt! { | ||
#[cfg_attr(not(all(tokio_unstable, feature = "tracing")), allow(unused_variables))] | ||
#[track_caller] | ||
pub(crate) fn new_timeout( | ||
deadline: Instant, | ||
location: Option<&'static Location<'static>>, | ||
) -> Sleep { | ||
use crate::runtime::Handle; | ||
|
||
let handle = Handle::current().inner; | ||
let entry = TimerEntry::new(&handle, deadline); | ||
|
||
#[cfg(all(tokio_unstable, feature = "tracing"))] | ||
let inner = { | ||
let handle = &handle.time(); | ||
let time_source = handle.time_source(); | ||
let deadline_tick = time_source.deadline_to_tick(deadline); | ||
let duration = deadline_tick.saturating_sub(time_source.now()); | ||
|
||
let location = location.expect("should have location if tracing"); | ||
let resource_span = tracing::trace_span!( | ||
"runtime.resource", | ||
concrete_type = "Sleep", | ||
kind = "timer", | ||
loc.file = location.file(), | ||
loc.line = location.line(), | ||
loc.col = location.column(), | ||
#[cfg_attr(not(all(tokio_unstable, feature = "tracing")), allow(unused_variables))] | ||
#[track_caller] | ||
pub(crate) fn new_timeout( | ||
deadline: Instant, | ||
location: Option<&'static Location<'static>>, | ||
) -> Sleep { | ||
use crate::runtime::scheduler; | ||
|
||
let handle = scheduler::Handle::current(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this change, the conditional compilation test complains that |
||
let entry = TimerEntry::new(&handle, deadline); | ||
|
||
#[cfg(all(tokio_unstable, feature = "tracing"))] | ||
let inner = { | ||
let handle = &handle.time(); | ||
let time_source = handle.time_source(); | ||
let deadline_tick = time_source.deadline_to_tick(deadline); | ||
let duration = deadline_tick.saturating_sub(time_source.now()); | ||
|
||
let location = location.expect("should have location if tracing"); | ||
let resource_span = tracing::trace_span!( | ||
"runtime.resource", | ||
concrete_type = "Sleep", | ||
kind = "timer", | ||
loc.file = location.file(), | ||
loc.line = location.line(), | ||
loc.col = location.column(), | ||
); | ||
|
||
let async_op_span = resource_span.in_scope(|| { | ||
tracing::trace!( | ||
target: "runtime::resource::state_update", | ||
duration = duration, | ||
duration.unit = "ms", | ||
duration.op = "override", | ||
); | ||
|
||
let async_op_span = resource_span.in_scope(|| { | ||
tracing::trace!( | ||
target: "runtime::resource::state_update", | ||
duration = duration, | ||
duration.unit = "ms", | ||
duration.op = "override", | ||
); | ||
|
||
tracing::trace_span!("runtime.resource.async_op", source = "Sleep::new_timeout") | ||
}); | ||
|
||
let async_op_poll_span = | ||
async_op_span.in_scope(|| tracing::trace_span!("runtime.resource.async_op.poll")); | ||
|
||
let ctx = trace::AsyncOpTracingCtx { | ||
async_op_span, | ||
async_op_poll_span, | ||
resource_span, | ||
}; | ||
|
||
Inner { | ||
deadline, | ||
ctx, | ||
} | ||
tracing::trace_span!("runtime.resource.async_op", source = "Sleep::new_timeout") | ||
}); | ||
|
||
let async_op_poll_span = | ||
async_op_span.in_scope(|| tracing::trace_span!("runtime.resource.async_op.poll")); | ||
|
||
let ctx = trace::AsyncOpTracingCtx { | ||
async_op_span, | ||
async_op_poll_span, | ||
resource_span, | ||
}; | ||
|
||
#[cfg(not(all(tokio_unstable, feature = "tracing")))] | ||
let inner = Inner { deadline }; | ||
Inner { deadline, ctx } | ||
}; | ||
|
||
Sleep { inner, entry } | ||
} | ||
} | ||
#[cfg(not(all(tokio_unstable, feature = "tracing")))] | ||
let inner = Inner { deadline }; | ||
|
||
cfg_not_rt! { | ||
#[track_caller] | ||
pub(crate) fn new_timeout( | ||
_deadline: Instant, | ||
_location: Option<&'static Location<'static>>, | ||
) -> Sleep { | ||
panic!("{}", crate::util::error::CONTEXT_MISSING_ERROR) | ||
} | ||
Sleep { inner, entry } | ||
} | ||
|
||
pub(crate) fn far_future(location: Option<&'static Location<'static>>) -> Sleep { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an existing test that expected
IO
to be spelled this way. Instead of updating the test, I changed the message back to what it was before.