mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-20 00:00:08 +02:00
rt: remove driver drop implementations (#5014)
Currently, drivers are responsible for clean up when they are dropped. This is possible today because each driver struct holds a reference to its internal handle. As part of an effort to decouple drivers from their handles, this patch removes the drop implementations for the time and IO driver in favor of having the scheduler explicitly call `shutdown()` as part of its shutdown process. The scheduler will hold a reference to both the driver and the driver handles, so in the future, it will be able to pass in the driver handles as part of the shutdown process.
This commit is contained in:
@@ -70,7 +70,6 @@ cfg_io_driver! {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(not(feature = "rt-multi-thread"), allow(dead_code))] // some features use this
|
||||
pub(crate) fn shutdown(&mut self) {
|
||||
match self {
|
||||
IoStack::Enabled(v) => v.shutdown(),
|
||||
@@ -230,21 +229,10 @@ cfg_time! {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: tokio-rs/tokio#4990, should the `current_thread` scheduler call this?
|
||||
cfg_rt_multi_thread! {
|
||||
pub(crate) fn shutdown(&mut self) {
|
||||
match self {
|
||||
TimeDriver::Enabled { driver, handle } => driver.shutdown(handle),
|
||||
TimeDriver::Disabled(v) => v.shutdown(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TimeDriver {
|
||||
fn drop(&mut self) {
|
||||
if let TimeDriver::Enabled { driver, handle } = self {
|
||||
driver.shutdown(handle);
|
||||
pub(crate) fn shutdown(&mut self) {
|
||||
match self {
|
||||
TimeDriver::Enabled { driver, handle } => driver.shutdown(handle),
|
||||
TimeDriver::Disabled(v) => v.shutdown(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,10 +322,7 @@ impl Driver {
|
||||
self.inner.park_timeout(duration)
|
||||
}
|
||||
|
||||
// TODO: tokio-rs/tokio#4990, should the `current_thread` scheduler call this?
|
||||
cfg_rt_multi_thread! {
|
||||
pub(crate) fn shutdown(&mut self) {
|
||||
self.inner.shutdown()
|
||||
}
|
||||
pub(crate) fn shutdown(&mut self) {
|
||||
self.inner.shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,12 +230,6 @@ impl Driver {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Driver {
|
||||
fn drop(&mut self) {
|
||||
self.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Driver {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Driver")
|
||||
|
||||
@@ -236,6 +236,11 @@ impl Drop for CurrentThread {
|
||||
// Submit metrics
|
||||
core.metrics.submit(&core.spawner.shared.worker_metrics);
|
||||
|
||||
// Shutdown the resource drivers
|
||||
if let Some(driver) = core.driver.as_mut() {
|
||||
driver.shutdown();
|
||||
}
|
||||
|
||||
(core, ())
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user