mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
rt: move park logic into runtime module (#5158)
The runtime is the primary user of parking. Moving park into runtime will help future cleanups around combining context entering w/ block_on calls.
This commit is contained in:
parent
d8ee205530
commit
467adec4e1
@ -11,7 +11,7 @@ cfg_rt! {
|
||||
cfg_not_rt! {
|
||||
#[track_caller]
|
||||
pub(crate) fn block_on<F: Future>(f: F) -> F::Output {
|
||||
let mut park = crate::park::thread::CachedParkThread::new();
|
||||
let mut park = crate::runtime::park::CachedParkThread::new();
|
||||
park.block_on(f).unwrap()
|
||||
}
|
||||
}
|
||||
|
@ -479,7 +479,6 @@ pub mod io;
|
||||
pub mod net;
|
||||
|
||||
mod loom;
|
||||
mod park;
|
||||
|
||||
cfg_process! {
|
||||
pub mod process;
|
||||
|
@ -1,37 +0,0 @@
|
||||
//! Abstraction over blocking and unblocking the current thread.
|
||||
//!
|
||||
//! Provides an abstraction over blocking the current thread. This is similar to
|
||||
//! the park / unpark constructs provided by `std` but made generic. This allows
|
||||
//! embedding custom functionality to perform when the thread is blocked.
|
||||
//!
|
||||
//! A blocked `Park` instance is unblocked by calling `unpark` on its
|
||||
//! `Unpark` handle.
|
||||
//!
|
||||
//! The `ParkThread` struct implements `Park` using `thread::park` to put the
|
||||
//! thread to sleep. The Tokio reactor also implements park, but uses
|
||||
//! `mio::Poll` to block the thread instead.
|
||||
//!
|
||||
//! The `Park` trait is composable. A timer implementation might decorate a
|
||||
//! `Park` implementation by checking if any timeouts have elapsed after the
|
||||
//! inner `Park` implementation unblocks.
|
||||
//!
|
||||
//! # Model
|
||||
//!
|
||||
//! Conceptually, each `Park` instance has an associated token, which is
|
||||
//! initially not present:
|
||||
//!
|
||||
//! * The `park` method blocks the current thread unless or until the token is
|
||||
//! available, at which point it atomically consumes the token.
|
||||
//! * The `unpark` method atomically makes the token available if it wasn't
|
||||
//! already.
|
||||
//!
|
||||
//! Some things to note:
|
||||
//!
|
||||
//! * If `unpark` is called before `park`, the next call to `park` will
|
||||
//! **not** block the thread.
|
||||
//! * **Spurious** wakeups are permitted, i.e., the `park` method may unblock
|
||||
//! even if `unpark` was not called.
|
||||
//! * `park_timeout` does the same as `park` but allows specifying a maximum
|
||||
//! time to block the thread for.
|
||||
|
||||
pub(crate) mod thread;
|
@ -4,7 +4,7 @@
|
||||
// don't need to worry much about dead code with certain feature permutations.
|
||||
#![cfg_attr(not(feature = "full"), allow(dead_code))]
|
||||
|
||||
use crate::park::thread::{ParkThread, UnparkThread};
|
||||
use crate::runtime::park::{ParkThread, UnparkThread};
|
||||
|
||||
use std::io;
|
||||
use std::time::Duration;
|
||||
|
@ -146,7 +146,7 @@ cfg_rt! {
|
||||
where
|
||||
F: std::future::Future,
|
||||
{
|
||||
use crate::park::thread::CachedParkThread;
|
||||
use crate::runtime::park::CachedParkThread;
|
||||
|
||||
let mut park = CachedParkThread::new();
|
||||
park.block_on(f)
|
||||
@ -160,7 +160,7 @@ cfg_rt! {
|
||||
where
|
||||
F: std::future::Future,
|
||||
{
|
||||
use crate::park::thread::CachedParkThread;
|
||||
use crate::runtime::park::CachedParkThread;
|
||||
use std::task::Context;
|
||||
use std::task::Poll::Ready;
|
||||
use std::time::Instant;
|
||||
|
@ -181,6 +181,8 @@ pub(crate) mod context;
|
||||
|
||||
pub(crate) mod coop;
|
||||
|
||||
pub(crate) mod park;
|
||||
|
||||
mod driver;
|
||||
|
||||
pub(crate) mod scheduler;
|
||||
|
@ -2,7 +2,7 @@ use crate::loom::cell::UnsafeCell;
|
||||
use crate::loom::future::AtomicWaker;
|
||||
use crate::loom::sync::atomic::AtomicUsize;
|
||||
use crate::loom::sync::Arc;
|
||||
use crate::park::thread::CachedParkThread;
|
||||
use crate::runtime::park::CachedParkThread;
|
||||
use crate::sync::mpsc::error::TryRecvError;
|
||||
use crate::sync::mpsc::{bounded, list, unbounded};
|
||||
use crate::sync::notify::Notify;
|
||||
|
Loading…
x
Reference in New Issue
Block a user