Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Tokio to Rust 2018 #1082

Merged
merged 46 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
50dab6f
async-await: replace std await! macro with await syntax
taiki-e May 9, 2019
91c69db
buf, io: update to Rust 2018
carllerche May 9, 2019
429851f
io: fix tests
carllerche May 9, 2019
cd260eb
sync: update to Rust 2018
carllerche May 9, 2019
9acaec4
executor: update to Rust 2018
carllerche May 9, 2019
ec682c5
reactor: update to Rust 2018
carllerche May 9, 2019
72a09e0
macros: tweaks
carllerche May 9, 2019
4f771a6
async-await: replace std_await! macro with await syntax
taiki-e May 9, 2019
29da8ac
codec: update to Rust 2018
carllerche May 9, 2019
908304c
current-thread: update to Rust 2018
carllerche May 9, 2019
4de9e11
threadpool: update to Rust 2018
carllerche May 9, 2019
6bd15b7
async-await: rename tokio::await! to async_wait!
taiki-e May 9, 2019
4d12639
all: update Cargo.toml versions + disable push
carllerche May 9, 2019
bf9c201
update dep versions in Cargo.toml files
carllerche May 9, 2019
df9a87f
fs: update to Rust 2018
carllerche May 10, 2019
d387ae7
Merge remote-tracking branch 'taiki-e/await' into rust-2018
carllerche May 10, 2019
7e9217f
futures: update to Rust 2018
carllerche May 10, 2019
3416d87
signal: update to Rust 2018
carllerche May 10, 2019
a19c118
tcp: update to Rust 2018
carllerche May 10, 2019
73ab0ef
timer: update to Rust 2018
carllerche May 10, 2019
6e68380
test: update to Rust 2018
carllerche May 10, 2019
814d876
tls: update to Rust 2018
carllerche May 10, 2019
95b8eee
udp: update to Rust 2018
carllerche May 10, 2019
05d348a
uds: update to Rust 2018
carllerche May 10, 2019
d2040b3
tokio: update to Rust 2018
carllerche May 10, 2019
d8a0b1f
fmt
carllerche May 10, 2019
55f7c74
fmt
carllerche May 10, 2019
611ade4
windows fixes
carllerche May 10, 2019
7cf9f86
linux fix
carllerche May 10, 2019
2a32934
misc ci fixes
carllerche May 10, 2019
6641f6c
misc fixes
carllerche May 10, 2019
0a12f4b
More fixes
carllerche May 10, 2019
778f9a0
win fix
carllerche May 10, 2019
3ea50d2
win fix
carllerche May 10, 2019
dbf3e3b
tsan whitelist
carllerche May 10, 2019
c33584d
more tsan whitelist
carllerche May 10, 2019
cd59434
Update tokio-signal/src/windows.rs
carllerche May 10, 2019
c84c285
Deny rust_2018_idioms for tokio doc tests
carllerche May 10, 2019
1505f8d
Work on updating docs
carllerche May 10, 2019
b3ffa7f
fs, io: update doc examples
carllerche May 10, 2019
2628120
more doc fixes
carllerche May 10, 2019
d6ed92e
more doc fixes
carllerche May 10, 2019
360ee74
hopefully all doc tests are updated
carllerche May 10, 2019
395b884
fmt
carllerche May 10, 2019
5152abb
Fix examples
carllerche May 10, 2019
ca8fa97
fix docs
carllerche May 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
reactor: update to Rust 2018
  • Loading branch information
carllerche committed May 9, 2019
commit ec682c5d05a7eebc6141b1948806e8b2022eb4ba
4 changes: 3 additions & 1 deletion tokio-reactor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ name = "tokio-reactor"
# - README.md
# - Update CHANGELOG.md.
# - Create "v0.1.x" git tag.
version = "0.1.9"
version = "0.2.0"
edition = "2018"
authors = ["Carl Lerche <me@carllerche.com>"]
license = "MIT"
readme = "README.md"
Expand All @@ -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"
Expand Down
8 changes: 1 addition & 7 deletions tokio-reactor/benches/basic.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 2 additions & 3 deletions tokio-reactor/src/background.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
41 changes: 12 additions & 29 deletions tokio-reactor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![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))]

//! Event loop that drives Tokio I/O resources.
//!
Expand Down Expand Up @@ -30,21 +31,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;
Expand All @@ -58,13 +44,14 @@ pub use self::registration::Registration;

// ===== Private imports =====

use sharded_rwlock::RwLock;

use crate::sharded_rwlock::RwLock;
use futures::task::Task;
use log::{debug, log_enabled, trace, Level};
use mio::event::Evented;
use tokio_executor::park::{Park, Unpark};
use tokio_executor::Enter;
use tokio_sync::task::AtomicTask;

use slab::Slab;
use std::cell::RefCell;
use std::error::Error;
use std::io;
Expand All @@ -77,10 +64,6 @@ use std::sync::{Arc, Weak};
use std::time::{Duration, Instant};
use std::{fmt, usize};

use log::Level;
use mio::event::Evented;
use slab::Slab;

/// The core reactor, or event loop.
///
/// The event loop is the main source of blocking in an application which drives
Expand Down Expand Up @@ -467,7 +450,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")
}
}
Expand Down Expand Up @@ -519,7 +502,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")
}
}
Expand Down Expand Up @@ -641,7 +624,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")
}
}
Expand All @@ -652,7 +635,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);

Expand Down Expand Up @@ -690,7 +673,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)
}

Expand Down Expand Up @@ -773,7 +756,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())
}
}
Expand Down
12 changes: 5 additions & 7 deletions tokio-reactor/src/poll_evented.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use {Handle, Registration};

use futures::{task, Async, Poll};
use crate::{Handle, Registration};
use futures::{try_ready, task, 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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -248,7 +246,7 @@ 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
Expand Down Expand Up @@ -473,7 +471,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()
}
}
Expand Down
7 changes: 3 additions & 4 deletions tokio-reactor/src/registration.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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];
Expand Down
15 changes: 8 additions & 7 deletions tokio-reactor/src/sharded_rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,9 +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.
///
Expand Down Expand Up @@ -65,7 +66,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);
Expand All @@ -84,7 +85,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`.
Expand All @@ -99,7 +100,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>>,
Expand All @@ -116,7 +117,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>>,
}
Expand Down