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
+13 -8
View File
@@ -4,9 +4,9 @@ use worker::state::{State, PUSHED_MASK};
use std::cell::UnsafeCell;
use std::fmt;
use std::sync::Arc;
use std::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed, Release};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::atomic::Ordering::{Acquire, AcqRel, Relaxed, Release};
use std::sync::Arc;
use std::time::Duration;
use crossbeam_deque::{Steal, Stealer, Worker};
@@ -102,9 +102,10 @@ impl WorkerEntry {
let mut next = state;
next.notify();
let actual = self.state.compare_and_swap(
state.into(), next.into(),
AcqRel).into();
let actual = self
.state
.compare_and_swap(state.into(), next.into(), AcqRel)
.into();
if state == actual {
break;
@@ -169,8 +170,10 @@ impl WorkerEntry {
next.set_lifecycle(Signaled);
let actual = self.state.compare_and_swap(
state.into(), next.into(), AcqRel).into();
let actual = self
.state
.compare_and_swap(state.into(), next.into(), AcqRel)
.into();
if actual == state {
break;
@@ -307,7 +310,9 @@ impl WorkerEntry {
#[inline]
pub fn set_next_sleeper(&self, val: usize) {
unsafe { *self.next_sleeper.get() = val; }
unsafe {
*self.next_sleeper.get() = val;
}
}
}
+32 -28
View File
@@ -2,24 +2,19 @@ mod entry;
mod stack;
mod state;
pub(crate) use self::entry::{
WorkerEntry as Entry,
};
pub(crate) use self::entry::WorkerEntry as Entry;
pub(crate) use self::stack::Stack;
pub(crate) use self::state::{
State,
Lifecycle,
};
pub(crate) use self::state::{Lifecycle, State};
use pool::{self, Pool, BackupId};
use notifier::Notifier;
use pool::{self, BackupId, Pool};
use sender::Sender;
use shutdown::ShutdownTrigger;
use task::{self, Task, CanBlock};
use task::{self, CanBlock, Task};
use tokio_executor;
use futures::{Poll, Async};
use futures::{Async, Poll};
use std::cell::Cell;
use std::marker::PhantomData;
@@ -339,8 +334,11 @@ impl Worker {
}
}
let actual = self.entry().state.compare_and_swap(
state.into(), next.into(), AcqRel).into();
let actual = self
.entry()
.state
.compare_and_swap(state.into(), next.into(), AcqRel)
.into();
if actual == state {
break;
@@ -417,8 +415,11 @@ impl Worker {
self.run_task(task, notify);
trace!("try_steal_task -- signal_work; self={}; from={}",
self.id.0, idx);
trace!(
"try_steal_task -- signal_work; self={}; from={}",
self.id.0,
idx
);
// Signal other workers that work is available
//
@@ -485,8 +486,11 @@ impl Worker {
let mut next = state;
next.dec_num_futures();
let actual = self.pool.state.compare_and_swap(
state.into(), next.into(), AcqRel).into();
let actual = self
.pool
.state
.compare_and_swap(state.into(), next.into(), AcqRel)
.into();
if actual == state {
trace!("task complete; state={:?}", next);
@@ -526,11 +530,7 @@ impl Worker {
///
/// Great care is needed to ensure that `current_task` is unset in this
/// function.
fn run_task2(&self,
task: &Arc<Task>,
notify: &Arc<Notifier>)
-> task::Run
{
fn run_task2(&self, task: &Arc<Task>, notify: &Arc<Notifier>) -> task::Run {
struct Guard<'a> {
worker: &'a Worker,
}
@@ -562,9 +562,7 @@ impl Worker {
// Create the guard, this ensures that `current_task` is unset when the
// function returns, even if the return is caused by a panic.
let _g = Guard {
worker: self,
};
let _g = Guard { worker: self };
task.run(notify)
}
@@ -609,8 +607,11 @@ impl Worker {
}
}
let actual = self.entry().state.compare_and_swap(
state.into(), next.into(), AcqRel).into();
let actual = self
.entry()
.state
.compare_and_swap(state.into(), next.into(), AcqRel)
.into();
if actual == state {
if state.is_notified() {
@@ -668,8 +669,11 @@ impl Worker {
let mut next = state;
next.set_lifecycle(Running);
let actual = self.entry().state.compare_and_swap(
state.into(), next.into(), AcqRel).into();
let actual = self
.entry()
.state
.compare_and_swap(state.into(), next.into(), AcqRel)
.into();
if actual == state {
return true;
+20 -13
View File
@@ -1,9 +1,9 @@
use config::MAX_WORKERS;
use worker;
use std::{fmt, usize};
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::{Acquire, AcqRel, Relaxed};
use std::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed};
use std::{fmt, usize};
/// Lock-free stack of sleeping workers.
///
@@ -90,8 +90,10 @@ impl Stack {
entries[idx].set_next_sleeper(head);
next.set_head(idx);
let actual = self.state.compare_and_swap(
state.into(), next.into(), AcqRel).into();
let actual = self
.state
.compare_and_swap(state.into(), next.into(), AcqRel)
.into();
if state == actual {
return Ok(());
@@ -112,11 +114,12 @@ impl Stack {
/// Returns the index of the popped worker and the worker's observed state.
///
/// `None` if the stack is empty.
pub fn pop(&self, entries: &[worker::Entry],
max_lifecycle: worker::Lifecycle,
terminate: bool)
-> Option<(usize, worker::State)>
{
pub fn pop(
&self,
entries: &[worker::Entry],
max_lifecycle: worker::Lifecycle,
terminate: bool,
) -> Option<(usize, worker::State)> {
// Figure out the empty value
let terminal = match terminate {
true => TERMINATED,
@@ -145,8 +148,10 @@ impl Stack {
return None;
}
let actual = self.state.compare_and_swap(
state.into(), next.into(), AcqRel).into();
let actual = self
.state
.compare_and_swap(state.into(), next.into(), AcqRel)
.into();
if actual != state {
state = actual;
@@ -173,8 +178,10 @@ impl Stack {
next.set_head(next_head);
}
let actual = self.state.compare_and_swap(
state.into(), next.into(), AcqRel).into();
let actual = self
.state
.compare_and_swap(state.into(), next.into(), AcqRel)
.into();
if actual == state {
// Release ordering is needed to ensure that unsetting the
+8 -13
View File
@@ -108,11 +108,12 @@ impl From<usize> for Lifecycle {
use self::Lifecycle::*;
debug_assert!(
src == Shutdown as usize ||
src == Running as usize ||
src == Sleeping as usize ||
src == Notified as usize ||
src == Signaled as usize);
src == Shutdown as usize
|| src == Running as usize
|| src == Sleeping as usize
|| src == Notified as usize
|| src == Signaled as usize
);
unsafe { ::std::mem::transmute(src) }
}
@@ -128,18 +129,12 @@ impl From<Lifecycle> for usize {
#[cfg(test)]
mod test {
use super::*;
use super::Lifecycle::*;
use super::*;
#[test]
fn lifecycle_encode() {
let lifecycles = &[
Shutdown,
Running,
Sleeping,
Notified,
Signaled,
];
let lifecycles = &[Shutdown, Running, Sleeping, Notified, Signaled];
for &lifecycle in lifecycles {
let mut v: usize = lifecycle.into();