diff options
Diffstat (limited to 'tokio-reactor')
-rw-r--r-- | tokio-reactor/Cargo.toml | 12 | ||||
-rw-r--r-- | tokio-reactor/benches/basic.rs | 8 | ||||
-rw-r--r-- | tokio-reactor/src/background.rs | 5 | ||||
-rw-r--r-- | tokio-reactor/src/lib.rs | 48 | ||||
-rw-r--r-- | tokio-reactor/src/poll_evented.rs | 17 | ||||
-rw-r--r-- | tokio-reactor/src/registration.rs | 7 | ||||
-rw-r--r-- | tokio-reactor/src/sharded_rwlock.rs | 16 |
7 files changed, 46 insertions, 67 deletions
diff --git a/tokio-reactor/Cargo.toml b/tokio-reactor/Cargo.toml index 0975ac5b..409bd39f 100644 --- a/tokio-reactor/Cargo.toml +++ b/tokio-reactor/Cargo.toml @@ -7,8 +7,9 @@ name = "tokio-reactor" # - Cargo.toml # - README.md # - Update CHANGELOG.md. -# - Create "v0.1.x" git tag. -version = "0.1.9" +# - Create "v0.2.x" git tag. +version = "0.2.0" +edition = "2018" authors = ["Carl Lerche <me@carllerche.com>"] license = "MIT" readme = "README.md" @@ -19,6 +20,7 @@ description = """ Event loop that drives Tokio I/O resources. """ categories = ["asynchronous", "network-programming"] +publish = false [dependencies] crossbeam-utils = "0.6.0" @@ -29,9 +31,9 @@ mio = "0.6.14" num_cpus = "1.8.0" parking_lot = "0.7.0" slab = "0.4.0" -tokio-executor = "0.1.1" -tokio-io = "0.1.6" -tokio-sync = "0.1.1" +tokio-executor = { version = "0.2.0", path = "../tokio-executor" } +tokio-io = { version = "0.2.0", path = "../tokio-io" } +tokio-sync = { version = "0.2.0", path = "../tokio-sync" } [dev-dependencies] num_cpus = "1.8.0" diff --git a/tokio-reactor/benches/basic.rs b/tokio-reactor/benches/basic.rs index 63020d2f..a126d133 100644 --- a/tokio-reactor/benches/basic.rs +++ b/tokio-reactor/benches/basic.rs @@ -1,13 +1,7 @@ #![feature(test)] -#![deny(warnings)] +#![deny(warnings, rust_2018_idioms)] -extern crate futures; -extern crate mio; -extern crate num_cpus; extern crate test; -extern crate tokio; -extern crate tokio_io_pool; -extern crate tokio_reactor; const NUM_YIELD: usize = 500; const TASKS_PER_CPU: usize = 100; diff --git a/tokio-reactor/src/background.rs b/tokio-reactor/src/background.rs index d4bfb78a..70e8ebd3 100644 --- a/tokio-reactor/src/background.rs +++ b/tokio-reactor/src/background.rs @@ -1,7 +1,6 @@ -use {AtomicTask, Handle, Reactor}; - +use crate::{AtomicTask, Handle, Reactor}; use futures::{task, Async, Future, Poll}; - +use log::debug; use std::io; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::SeqCst; diff --git a/tokio-reactor/src/lib.rs b/tokio-reactor/src/lib.rs index 15ea8fd2..fb8f3531 100644 --- a/tokio-reactor/src/lib.rs +++ b/tokio-reactor/src/lib.rs @@ -1,5 +1,7 @@ #![doc(html_root_url = "https://docs.rs/tokio-reactor/0.1.9")] -#![deny(missing_docs, warnings, missing_debug_implementations)] +#![deny(missing_docs, missing_debug_implementations, rust_2018_idioms)] +#![cfg_attr(test, deny(warnings))] +#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] //! Event loop that drives Tokio I/O resources. //! @@ -30,21 +32,6 @@ //! [`PollEvented`]: struct.PollEvented.html //! [reactor module]: https://docs.rs/tokio/0.1/tokio/reactor/index.html -extern crate crossbeam_utils; -#[macro_use] -extern crate futures; -#[macro_use] -extern crate lazy_static; -#[macro_use] -extern crate log; -extern crate mio; -extern crate num_cpus; -extern crate parking_lot; -extern crate slab; -extern crate tokio_executor; -extern crate tokio_io; -extern crate tokio_sync; - pub(crate) mod background; mod poll_evented; mod registration; @@ -58,13 +45,11 @@ pub use self::registration::Registration; // ===== Private imports ===== -use sharded_rwlock::RwLock; - +use crate::sharded_rwlock::RwLock; use futures::task::Task; -use tokio_executor::park::{Park, Unpark}; -use tokio_executor::Enter; -use tokio_sync::task::AtomicTask; - +use log::{debug, log_enabled, trace, Level}; +use mio::event::Evented; +use slab::Slab; use std::cell::RefCell; use std::error::Error; use std::io; @@ -76,10 +61,9 @@ use std::sync::atomic::Ordering::{Relaxed, SeqCst}; use std::sync::{Arc, Weak}; use std::time::{Duration, Instant}; use std::{fmt, usize}; - -use log::Level; -use mio::event::Evented; -use slab::Slab; +use tokio_executor::park::{Park, Unpark}; +use tokio_executor::Enter; +use tokio_sync::task::AtomicTask; /// The core reactor, or event loop. /// @@ -467,7 +451,7 @@ impl Park for Reactor { } impl fmt::Debug for Reactor { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Reactor") } } @@ -519,7 +503,7 @@ impl Default for Handle { } impl fmt::Debug for Handle { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Handle") } } @@ -641,7 +625,7 @@ impl HandlePriv { } impl fmt::Debug for HandlePriv { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "HandlePriv") } } @@ -652,7 +636,7 @@ impl Inner { /// Register an I/O resource with the reactor. /// /// The registration token is returned. - fn add_source(&self, source: &Evented) -> io::Result<usize> { + fn add_source(&self, source: &dyn Evented) -> io::Result<usize> { // Get an ABA guard value let aba_guard = self.next_aba_guard.fetch_add(1 << TOKEN_SHIFT, Relaxed); @@ -690,7 +674,7 @@ impl Inner { } /// Deregisters an I/O resource from the reactor. - fn deregister_source(&self, source: &Evented) -> io::Result<()> { + fn deregister_source(&self, source: &dyn Evented) -> io::Result<()> { self.io.deregister(source) } @@ -773,7 +757,7 @@ mod platform { // ===== impl SetFallbackError ===== impl fmt::Display for SetFallbackError { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "{}", self.description()) } } diff --git a/tokio-reactor/src/poll_evented.rs b/tokio-reactor/src/poll_evented.rs index 230f7c34..140ac4ca 100644 --- a/tokio-reactor/src/poll_evented.rs +++ b/tokio-reactor/src/poll_evented.rs @@ -1,14 +1,12 @@ -use {Handle, Registration}; - -use futures::{task, Async, Poll}; +use crate::{Handle, Registration}; +use futures::{task, try_ready, Async, Poll}; use mio; use mio::event::Evented; -use tokio_io::{AsyncRead, AsyncWrite}; - use std::fmt; use std::io::{self, Read, Write}; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::Relaxed; +use tokio_io::{AsyncRead, AsyncWrite}; /// Associates an I/O resource that implements the [`std::io::Read`] and/or /// [`std::io::Write`] traits with the reactor that drives it. @@ -108,7 +106,7 @@ macro_rules! poll_ready { // Load cached & encoded readiness. let mut cached = $me.inner.$cache.load(Relaxed); - let mask = $mask | ::platform::hup(); + let mask = $mask | crate::platform::hup(); // See if the current readiness matches any bits. let mut ret = mio::Ready::from_usize(cached) & $mask; @@ -248,7 +246,10 @@ where pub fn clear_read_ready(&self, ready: mio::Ready) -> io::Result<()> { // Cannot clear write readiness assert!(!ready.is_writable(), "cannot clear write readiness"); - assert!(!::platform::is_hup(&ready), "cannot clear HUP readiness"); + assert!( + !crate::platform::is_hup(&ready), + "cannot clear HUP readiness" + ); self.inner .read_readiness @@ -473,7 +474,7 @@ fn is_wouldblock<T>(r: &io::Result<T>) -> bool { } impl<E: Evented + fmt::Debug> fmt::Debug for PollEvented<E> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("PollEvented").field("io", &self.io).finish() } } diff --git a/tokio-reactor/src/registration.rs b/tokio-reactor/src/registration.rs index 4ad9f086..3b7e8391 100644 --- a/tokio-reactor/src/registration.rs +++ b/tokio-reactor/src/registration.rs @@ -1,8 +1,7 @@ -use {Direction, Handle, HandlePriv, Task}; - +use crate::{Direction, Handle, HandlePriv, Task}; use futures::{task, Async, Poll}; +use log::debug; use mio::{self, Evented}; - use std::cell::UnsafeCell; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::SeqCst; @@ -498,7 +497,7 @@ impl Inner { }; let mask = direction.mask(); - let mask_no_hup = (mask - ::platform::hup()).as_usize(); + let mask_no_hup = (mask - crate::platform::hup()).as_usize(); let io_dispatch = inner.io_dispatch.read(); let sched = &io_dispatch[self.token]; diff --git a/tokio-reactor/src/sharded_rwlock.rs b/tokio-reactor/src/sharded_rwlock.rs index 6b6207b5..ec16fb13 100644 --- a/tokio-reactor/src/sharded_rwlock.rs +++ b/tokio-reactor/src/sharded_rwlock.rs @@ -4,6 +4,10 @@ //! while making write operations slower. It also incurs much higher memory overhead than //! traditional reader-writer locks. +use crossbeam_utils::CachePadded; +use lazy_static::lazy_static; +use num_cpus; +use parking_lot; use std::cell::UnsafeCell; use std::collections::HashMap; use std::marker::PhantomData; @@ -12,10 +16,6 @@ use std::ops::{Deref, DerefMut}; use std::sync::Mutex; use std::thread::{self, ThreadId}; -use crossbeam_utils::CachePadded; -use num_cpus; -use parking_lot; - /// A scalable read-writer lock. /// /// This type of lock allows a number of readers or at most one writer at any point in time. The @@ -65,7 +65,7 @@ impl<T> RwLock<T> { /// or writers will acquire the lock first. /// /// Returns an RAII guard which will release this thread's shared access once it is dropped. - pub fn read(&self) -> RwLockReadGuard<T> { + pub fn read(&self) -> RwLockReadGuard<'_, T> { // Take the current thread index and map it to a shard index. Thread indices will tend to // distribute shards among threads equally, thus reducing contention due to read-locking. let shard_index = thread_index() & (self.shards.len() - 1); @@ -84,7 +84,7 @@ impl<T> RwLock<T> { /// the lock. /// /// Returns an RAII guard which will drop the write access of this rwlock when dropped. - pub fn write(&self) -> RwLockWriteGuard<T> { + pub fn write(&self) -> RwLockWriteGuard<'_, T> { // Write-lock each shard in succession. for shard in &self.shards { // The write guard is forgotten, but the lock will be manually unlocked in `drop`. @@ -99,7 +99,7 @@ impl<T> RwLock<T> { } /// A guard used to release the shared read access of a `RwLock` when dropped. -pub struct RwLockReadGuard<'a, T: 'a> { +pub struct RwLockReadGuard<'a, T> { parent: &'a RwLock<T>, _guard: parking_lot::RwLockReadGuard<'a, ()>, _marker: PhantomData<parking_lot::RwLockReadGuard<'a, T>>, @@ -116,7 +116,7 @@ impl<'a, T> Deref for RwLockReadGuard<'a, T> { } /// A guard used to release the exclusive write access of a `RwLock` when dropped. -pub struct RwLockWriteGuard<'a, T: 'a> { +pub struct RwLockWriteGuard<'a, T> { parent: &'a RwLock<T>, _marker: PhantomData<parking_lot::RwLockWriteGuard<'a, T>>, } |