Update Tokio to Rust 2018 (#1082)

This commit is contained in:
Carl Lerche
2019-05-14 10:27:36 -07:00
committed by GitHub
parent 79d8820050
commit cb4aea394e
343 changed files with 1725 additions and 2813 deletions
+2 -3
View File
@@ -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;
+16 -32
View File
@@ -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())
}
}
+9 -8
View File
@@ -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()
}
}
+3 -4
View File
@@ -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];
+8 -8
View File
@@ -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>>,
}