chore: apply rustfmt to all crates (#917)

This commit is contained in:
Carl Lerche
2019-02-21 11:56:15 -08:00
committed by GitHub
parent ab595d0825
commit 80162306e7
253 changed files with 3710 additions and 3407 deletions
+5 -3
View File
@@ -1,10 +1,10 @@
use Error;
use super::Entry;
use Error;
use std::ptr;
use std::sync::Arc;
use std::sync::atomic::AtomicPtr;
use std::sync::atomic::Ordering::SeqCst;
use std::sync::Arc;
/// A stack of `Entry` nodes
#[derive(Debug)]
@@ -24,7 +24,9 @@ const SHUTDOWN: *mut Entry = 1 as *mut _;
impl AtomicStack {
pub fn new() -> AtomicStack {
AtomicStack { head: AtomicPtr::new(ptr::null_mut()) }
AtomicStack {
head: AtomicPtr::new(ptr::null_mut()),
}
}
/// Push an entry onto the stack.
+15 -22
View File
@@ -1,17 +1,17 @@
use Error;
use atomic::AtomicU64;
use timer::{HandlePriv, Inner};
use Error;
use crossbeam_utils::CachePadded;
use futures::Poll;
use futures::task::AtomicTask;
use futures::Poll;
use std::cell::UnsafeCell;
use std::ptr;
use std::sync::{Arc, Weak};
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::{SeqCst, Relaxed};
use std::time::{Instant, Duration};
use std::sync::atomic::Ordering::{Relaxed, SeqCst};
use std::sync::{Arc, Weak};
use std::time::{Duration, Instant};
use std::u64;
/// Internal state shared between a `Delay` instance and the timer.
@@ -109,10 +109,7 @@ const ERROR: u64 = u64::MAX;
impl Entry {
pub fn new(deadline: Instant, duration: Duration) -> Entry {
Entry {
time: CachePadded::new(UnsafeCell::new(Time {
deadline,
duration,
})),
time: CachePadded::new(UnsafeCell::new(Time { deadline, duration })),
inner: None,
task: AtomicTask::new(),
state: AtomicU64::new(0),
@@ -147,8 +144,7 @@ impl Entry {
Err(_) => {
// Could not associate the entry with a timer, transition the
// state to error
Arc::get_mut(me).unwrap()
.transition_to_error();
Arc::get_mut(me).unwrap().transition_to_error();
return;
}
@@ -168,8 +164,7 @@ impl Entry {
None => {
// Could not associate the entry with a timer, transition the
// state to error
Arc::get_mut(me).unwrap()
.transition_to_error();
Arc::get_mut(me).unwrap().transition_to_error();
return;
}
@@ -177,15 +172,13 @@ impl Entry {
// Increment the number of active timeouts
if inner.increment().is_err() {
Arc::get_mut(me).unwrap()
.transition_to_error();
Arc::get_mut(me).unwrap().transition_to_error();
return;
}
// Associate the entry with the timer
Arc::get_mut(me).unwrap()
.inner = Some(handle.into_inner());
Arc::get_mut(me).unwrap().inner = Some(handle.into_inner());
let when = inner.normalize_deadline(deadline);
@@ -216,7 +209,9 @@ impl Entry {
}
pub fn set_when_internal(&self, when: Option<u64>) {
unsafe { (*self.when.get()) = when; }
unsafe {
(*self.when.get()) = when;
}
}
/// Called by `Timer` to load the current value of `state` for processing
@@ -361,8 +356,7 @@ impl Entry {
notify = true;
}
let actual = entry.state.compare_and_swap(
curr, next, SeqCst);
let actual = entry.state.compare_and_swap(curr, next, SeqCst);
if curr == actual {
break;
@@ -377,8 +371,7 @@ impl Entry {
}
fn upgrade_inner(&self) -> Option<Arc<Inner>> {
self.inner.as_ref()
.and_then(|inner| inner.upgrade())
self.inner.as_ref().and_then(|inner| inner.upgrade())
}
}
+21 -22
View File
@@ -1,5 +1,5 @@
use {Error, Delay, Deadline, Interval};
use timer::Inner;
use {Deadline, Delay, Error, Interval};
use tokio_executor::Enter;
@@ -44,7 +44,7 @@ pub(crate) struct HandlePriv {
inner: Weak<Inner>,
}
thread_local!{
thread_local! {
/// Tracks the timer for the current execution context.
static CURRENT_TIMER: RefCell<Option<HandlePriv>> = RefCell::new(None)
}
@@ -61,7 +61,8 @@ thread_local!{
/// [`Delay`]: ../struct.Delay.html
/// [`Delay::new`]: ../struct.Delay.html#method.new
pub fn with_default<F, R>(handle: &Handle, enter: &mut Enter, f: F) -> R
where F: FnOnce(&mut Enter) -> R
where
F: FnOnce(&mut Enter) -> R,
{
// Ensure that the timer is removed from the thread-local context
// when leaving the scope. This handles cases that involve panicking.
@@ -84,10 +85,14 @@ where F: FnOnce(&mut Enter) -> R
{
let mut current = current.borrow_mut();
assert!(current.is_none(), "default Tokio timer already set \
for execution context");
assert!(
current.is_none(),
"default Tokio timer already set \
for execution context"
);
let handle = handle.as_priv()
let handle = handle
.as_priv()
.unwrap_or_else(|| panic!("`handle` does not reference a timer"));
*current = Some(handle.clone());
@@ -118,23 +123,19 @@ impl Handle {
/// [`with_default`]: ../fn.with_default.html
/// [type]: #
pub fn current() -> Handle {
let private = HandlePriv::try_current()
.unwrap_or_else(|_| {
HandlePriv { inner: Weak::new() }
});
let private =
HandlePriv::try_current().unwrap_or_else(|_| HandlePriv { inner: Weak::new() });
Handle { inner: Some(private) }
Handle {
inner: Some(private),
}
}
/// Create a `Delay` driven by this handle's associated `Timer`.
pub fn delay(&self, deadline: Instant) -> Delay {
match self.inner {
Some(ref handle_priv) => {
Delay::new_with_handle(deadline, handle_priv.clone())
}
None => {
Delay::new(deadline)
}
Some(ref handle_priv) => Delay::new_with_handle(deadline, handle_priv.clone()),
None => Delay::new(deadline),
}
}
@@ -165,11 +166,9 @@ impl HandlePriv {
///
/// Returns `Err` if no handle is found.
pub(crate) fn try_current() -> Result<HandlePriv, Error> {
CURRENT_TIMER.with(|current| {
match *current.borrow() {
Some(ref handle) => Ok(handle.clone()),
None => Err(Error::shutdown()),
}
CURRENT_TIMER.with(|current| match *current.borrow() {
Some(ref handle) => Ok(handle.clone()),
None => Err(Error::shutdown()),
})
}
+16 -15
View File
@@ -44,23 +44,23 @@ use self::atomic_stack::AtomicStack;
use self::entry::Entry;
use self::stack::Stack;
pub use self::handle::{Handle, with_default};
pub(crate) use self::handle::HandlePriv;
pub use self::handle::{with_default, Handle};
pub use self::now::{Now, SystemNow};
pub(crate) use self::registration::Registration;
use Error;
use atomic::AtomicU64;
use wheel;
use Error;
use tokio_executor::park::{Park, Unpark, ParkThread};
use tokio_executor::park::{Park, ParkThread, Unpark};
use std::{cmp, fmt};
use std::time::{Duration, Instant};
use std::sync::Arc;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::SeqCst;
use std::sync::Arc;
use std::time::{Duration, Instant};
use std::usize;
use std::{cmp, fmt};
/// Timer implementation that drives [`Delay`], [`Interval`], and [`Timeout`].
///
@@ -171,7 +171,8 @@ const MAX_TIMEOUTS: usize = usize::MAX >> 1;
// ===== impl Timer =====
impl<T> Timer<T>
where T: Park
where
T: Park,
{
/// Create a new `Timer` instance that uses `park` to block the current
/// thread.
@@ -201,8 +202,9 @@ impl<T, N> Timer<T, N> {
}
impl<T, N> Timer<T, N>
where T: Park,
N: Now,
where
T: Park,
N: Now,
{
/// Create a new `Timer` instance that uses `park` to block the current
/// thread and `now` to get the current `Instant`.
@@ -268,8 +270,7 @@ where T: Park,
let mut poll = wheel::Poll::new(now);
while let Some(entry) = self.wheel.poll(&mut poll, &mut ()) {
let when = entry.when_internal()
.expect("invalid internal entry state");
let when = entry.when_internal().expect("invalid internal entry state");
// Fire the entry
entry.fire(when);
@@ -345,8 +346,9 @@ impl Default for Timer<ParkThread, SystemNow> {
}
impl<T, N> Park for Timer<T, N>
where T: Park,
N: Now,
where
T: Park,
N: Now,
{
type Unpark = T::Unpark;
type Error = T::Error;
@@ -483,7 +485,6 @@ impl Inner {
impl fmt::Debug for Inner {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("Inner")
.finish()
fmt.debug_struct("Inner").finish()
}
}
+1 -1
View File
@@ -7,4 +7,4 @@ pub trait Now {
fn now(&mut self) -> Instant;
}
pub use ::clock::Clock as SystemNow;
pub use clock::Clock as SystemNow;
+6 -4
View File
@@ -1,11 +1,11 @@
use Error;
use clock::now;
use timer::{HandlePriv, Entry};
use timer::{Entry, HandlePriv};
use Error;
use futures::Poll;
use std::sync::Arc;
use std::time::{Instant, Duration};
use std::time::{Duration, Instant};
/// Registration with a timer.
///
@@ -21,7 +21,9 @@ impl Registration {
fn is_send<T: Send + Sync>() {}
is_send::<Registration>();
Registration { entry: Arc::new(Entry::new(deadline, duration)) }
Registration {
entry: Arc::new(Entry::new(deadline, duration)),
}
}
pub fn deadline(&self) -> Instant {
+1 -3
View File
@@ -49,7 +49,6 @@ impl wheel::Stack for Stack {
// Set this entry's next pointer
*entry.next_stack.get() = old;
}
// Update the head pointer
@@ -117,7 +116,6 @@ impl wheel::Stack for Stack {
}
fn when(item: &Entry, _: &()) -> u64 {
item.when_internal()
.expect("invalid internal state")
item.when_internal().expect("invalid internal state")
}
}