Skip to content

Commit

Permalink
timer: move tokio-timer into tokio crate
Browse files Browse the repository at this point in the history
A step towards collapsing Tokio sub crates into a single `tokio`
crate (#1318).

The `timer` implementation is now provided by the main `tokio` crate.
The `timer` functionality may still be excluded from the build by
skipping the `timer` feature flag.
  • Loading branch information
carllerche committed Oct 21, 2019
1 parent ed5a94e commit eb7d787
Show file tree
Hide file tree
Showing 37 changed files with 184 additions and 236 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ members = [
"tokio-net",
"tokio-sync",
"tokio-test",
"tokio-timer",
"tokio-tls",
"build-tests",
]
1 change: 0 additions & 1 deletion ci/patch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ tokio-io = { path = "tokio-io" }
tokio-macros = { path = "tokio-macros" }
tokio-net = { path = "tokio-net" }
tokio-sync = { path = "tokio-sync" }
tokio-timer = { path = "tokio-timer" }
tokio-tls = { path = "tokio-tls" }
1 change: 0 additions & 1 deletion tokio-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ tokio = { version = "=0.2.0-alpha.6", path = "../tokio" }
tokio-executor = { version = "=0.2.0-alpha.6", path = "../tokio-executor" }
tokio-io = { version = "=0.2.0-alpha.6", path = "../tokio-io" }
tokio-sync = { version = "=0.2.0-alpha.6", path = "../tokio-sync" }
tokio-timer = { version = "=0.3.0-alpha.6", path = "../tokio-timer" }

futures-core-preview = "=0.3.0-alpha.19"
pin-convert = "0.1.0"
Expand Down
8 changes: 4 additions & 4 deletions tokio-test/src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
//! });
//! ```

use tokio::timer::clock::{Clock, Now};
use tokio::timer::Timer;
use tokio_executor::park::{Park, Unpark};
use tokio_timer::clock::{Clock, Now};
use tokio_timer::Timer;

use std::marker::PhantomData;
use std::rc::Rc;
Expand Down Expand Up @@ -125,13 +125,13 @@ impl MockClock {
where
F: FnOnce(&mut Handle) -> R,
{
::tokio_timer::clock::with_default(&self.clock, || {
tokio::timer::clock::with_default(&self.clock, || {
let park = self.time.mock_park();
let timer = Timer::new(park);
let handle = timer.handle();
let time = self.time.clone();

let _timer = ::tokio_timer::set_default(&handle);
let _timer = tokio::timer::set_default(&handle);
let mut handle = Handle::new(timer, time);
f(&mut handle)
// lazy(|| Ok::<_, ()>(f(&mut handle))).wait().unwrap()
Expand Down
10 changes: 5 additions & 5 deletions tokio-test/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
//! [`AsyncRead`]: tokio_io::AsyncRead
//! [`AsyncWrite`]: tokio_io::AsyncWrite

use tokio::timer::{clock, timer, Delay};
use tokio_io::{AsyncRead, AsyncWrite, Buf};
use tokio_sync::mpsc;

use futures_core::ready;
use std::collections::VecDeque;
use std::future::Future;
use std::pin::Pin;
use std::task::{self, Poll, Waker};
use std::time::{Duration, Instant};
use std::{cmp, io};

use futures_core::ready;
use tokio_io::{AsyncRead, AsyncWrite, Buf};
use tokio_sync::mpsc;
use tokio_timer::{clock, timer, Delay};

/// An I/O object that follows a predefined script.
///
/// This value is created by `Builder` and implements `AsyncRead` + `AsyncWrite`. It
Expand Down
105 changes: 0 additions & 105 deletions tokio-timer/src/lib.rs

This file was deleted.

6 changes: 4 additions & 2 deletions tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ rt-full = [
signal = ["tokio-net/signal"]
sync = ["tokio-sync"]
tcp = ["io", "tokio-net/tcp"]
timer = ["tokio-timer"]
timer = ["crossbeam-utils", "slab"]
tracing = ["tracing-core"]
udp = ["io", "tokio-net/udp"]
uds = ["io", "tokio-net/uds"]
Expand All @@ -72,15 +72,17 @@ futures-util-preview = { version = "=0.3.0-alpha.19", features = ["sink"] }

# Everything else is optional...
bytes = { version = "0.4", optional = true }
crossbeam-utils = { version = "0.6.0", optional = true }
num_cpus = { version = "1.8.0", optional = true }
# Backs `DelayQueue`
slab = { version = "0.4.1", optional = true }
tokio-codec = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-codec" }
tokio-fs = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-fs" }
tokio-io = { version = "=0.2.0-alpha.6", optional = true, features = ["util"], path = "../tokio-io" }
tokio-executor = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-executor" }
tokio-macros = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-macros" }
tokio-net = { version = "=0.2.0-alpha.6", optional = true, features = ["async-traits"], path = "../tokio-net" }
tokio-sync = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-sync", features = ["async-traits"] }
tokio-timer = { version = "=0.3.0-alpha.6", optional = true, path = "../tokio-timer", features = ["async-traits"] }
tracing-core = { version = "0.1", optional = true }

[target.'cfg(feature = "tracing")'.dependencies]
Expand Down
7 changes: 3 additions & 4 deletions tokio/src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
//!
//! This module provides the [`now`][n] function, which returns an `Instant`
//! representing "now". The source of time used by this function is configurable
//! (via the [`tokio-timer`] crate) and allows mocking out the source of time in
//! tests or performing caching operations to reduce the number of syscalls.
//! and allows mocking out the source of time in tests or performing caching
//! operations to reduce the number of syscalls.
//!
//! Note that, because the source of time is configurable, it is possible to
//! observe non-monotonic behavior when calling [`now`][n] from different
//! executors.
//!
//! [n]: fn.now.html
//! [`tokio-timer`]: https://docs.rs/tokio-timer/0.2/tokio_timer/clock/index.html

pub use tokio_timer::clock::now;
pub use crate::timer::clock::now;
2 changes: 1 addition & 1 deletion tokio/src/future.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Asynchronous values.

#[cfg(feature = "timer")]
use tokio_timer::Timeout;
use crate::timer::Timeout;

#[cfg(feature = "timer")]
use std::time::Duration;
Expand Down
8 changes: 4 additions & 4 deletions tokio/src/runtime/current_thread/builder.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::runtime::current_thread::Runtime;
use crate::timer::clock::Clock;
use crate::timer::timer::Timer;

use tokio_executor::current_thread::CurrentThread;
use tokio_net::driver::Reactor;
use tokio_timer::clock::Clock;
use tokio_timer::timer::Timer;

use std::io;

Expand All @@ -24,7 +24,7 @@ use std::io;
///
/// ```
/// use tokio::runtime::current_thread::Builder;
/// use tokio_timer::clock::Clock;
/// use tokio::timer::clock::Clock;
///
/// # pub fn main() {
/// // build Runtime
Expand Down Expand Up @@ -66,7 +66,7 @@ impl Builder {

// Place a timer wheel on top of the reactor. If there are no timeouts to fire, it'll let the
// reactor pick up some new external events.
let timer = Timer::new_with_now(reactor, self.clock.clone());
let timer = Timer::new_with_clock(reactor, self.clock.clone());
let timer_handle = timer.handle();

// And now put a single-threaded executor on top of the timer. When there are no futures ready
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/runtime/current_thread/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::runtime::current_thread::Builder;
use crate::timer::clock::{self, Clock};
use crate::timer::timer::{self, Timer};

use tokio_executor::current_thread::Handle as ExecutorHandle;
use tokio_executor::current_thread::{self, CurrentThread};
use tokio_net::driver::{self, Reactor};
use tokio_timer::clock::{self, Clock};
use tokio_timer::timer::{self, Timer};

use std::error::Error;
use std::fmt;
Expand Down
3 changes: 1 addition & 2 deletions tokio/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//!
//! * Spawn a background thread running a [`Reactor`] instance.
//! * Start a [`ThreadPool`] for executing futures.
//! * Run an instance of [`Timer`] **per** thread pool worker thread.
//! * Run an instance of `Timer` **per** thread pool worker thread.
//!
//! The thread pool uses a work-stealing strategy and is configured to start a
//! worker thread for each CPU core available on the system. This tends to be
Expand Down Expand Up @@ -127,7 +127,6 @@
//! [`ThreadPool`]: https://docs.rs/tokio-executor/0.2.0-alpha.2/tokio_executor/threadpool/struct.ThreadPool.html
//! [`run`]: fn.run.html
//! [`tokio::spawn`]: ../executor/fn.spawn.html
//! [`Timer`]: https://docs.rs/tokio-timer/0.2/tokio_timer/timer/struct.Timer.html
//! [`tokio::main`]: ../../tokio_macros/attr.main.html

pub mod current_thread;
Expand Down
8 changes: 4 additions & 4 deletions tokio/src/runtime/threadpool/builder.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::{Inner, Runtime};
use crate::timer::clock::{self, Clock};
use crate::timer::timer::{self, Timer};

use tokio_executor::thread_pool;
use tokio_net::driver::{self, Reactor};
use tokio_timer::clock::{self, Clock};
use tokio_timer::timer::{self, Timer};

use tracing_core as trace;
use std::{fmt, io};
Expand All @@ -26,7 +26,7 @@ use std::sync::{Arc, Mutex};
///
/// ```
/// use tokio::runtime::Builder;
/// use tokio_timer::clock::Clock;
/// use tokio::timer::clock::Clock;
///
/// fn main() {
/// // build Runtime
Expand Down Expand Up @@ -233,7 +233,7 @@ impl Builder {
reactor_handles.push(reactor.handle());

// Create a new timer.
let timer = Timer::new_with_now(reactor, self.clock.clone());
let timer = Timer::new_with_clock(reactor, self.clock.clone());
timer_handles.push(timer.handle());
timers.push(Mutex::new(Some(timer)));
}
Expand Down
3 changes: 2 additions & 1 deletion tokio/src/runtime/threadpool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ pub use self::spawner::Spawner;
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411
pub use tokio_executor::thread_pool::JoinHandle;

use crate::timer::timer;

use tokio_executor::thread_pool::ThreadPool;
use tokio_net::driver;
use tokio_timer::timer;

use tracing_core as trace;
use std::future::Future;
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::time::Duration;

#[cfg(feature = "timer")]
use tokio_timer::{throttle::Throttle, Timeout};
use crate::timer::{throttle::Throttle, Timeout};

#[doc(inline)]
pub use futures_core::Stream;
Expand Down
File renamed without changes.
10 changes: 1 addition & 9 deletions tokio-timer/src/clock/mod.rs → tokio/src/timer/clock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod now;

pub use self::now::Now;

use crate::timer;
use std::cell::Cell;
use std::fmt;
use std::sync::Arc;
Expand Down Expand Up @@ -57,7 +56,7 @@ thread_local! {
/// # Examples
///
/// ```
/// # use tokio_timer::clock;
/// # use tokio::timer::clock;
/// let now = clock::now();
/// ```
pub fn now() -> Instant {
Expand Down Expand Up @@ -102,13 +101,6 @@ impl Clock {
}
}

#[allow(deprecated)]
impl timer::Now for Clock {
fn now(&mut self) -> Instant {
Clock::now(self)
}
}

impl fmt::Debug for Clock {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Clock")
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions tokio-timer/src/delay.rs → tokio/src/timer/delay.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::timer::{HandlePriv, Registration};
use crate::timer::timer::{HandlePriv, Registration};

use futures_core::ready;
use std::future::Future;
use std::pin::Pin;
Expand Down Expand Up @@ -78,8 +79,6 @@ impl Delay {
self.registration.reset(deadline);
}

// Used by `Timeout<Stream>`
#[cfg(feature = "async-traits")]
pub(crate) fn reset_timeout(&mut self) {
self.registration.reset_timeout();
}
Expand Down
Loading

0 comments on commit eb7d787

Please sign in to comment.