Skip to content

Commit 9e4b1af

Browse files
committed
cargo fmt --all
1 parent a68b05c commit 9e4b1af

File tree

138 files changed

+4712
-3101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+4712
-3101
lines changed

examples/cpu_monitor.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ pub struct Args {
3535
}
3636

3737
fn main() {
38-
let args: &Args =
39-
&Docopt::new(USAGE).and_then(|d| d.deserialize()).unwrap_or_else(|e| e.exit());
38+
let args: &Args = &Docopt::new(USAGE)
39+
.and_then(|d| d.deserialize())
40+
.unwrap_or_else(|e| e.exit());
4041

4142
match &args.arg_scenario[..] {
4243
"tasks_ended" => tasks_ended(args),
@@ -80,7 +81,7 @@ fn task_stall_root(args: &Args) {
8081

8182
fn task_stall_scope(args: &Args) {
8283
rayon::scope(|scope| {
83-
scope.spawn(move |_| task(args));
84-
scope.spawn(move |_| wait_for_user());
85-
});
84+
scope.spawn(move |_| task(args));
85+
scope.spawn(move |_| wait_for_user());
86+
});
8687
}

rayon-core/src/compile_fail/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// These modules contain `compile_fail` doc tests.
32
mod quicksort_race1;
43
mod quicksort_race2;

rayon-core/src/internal/task.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,3 @@ pub trait ToScopeHandle<'scope> {
8181
/// Convert the receiver into a scope handle.
8282
fn to_scope_handle(&self) -> Self::ScopeHandle;
8383
}
84-

rayon-core/src/internal/worker.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
//! worker thread. Intended for building abstractions atop the
33
//! rayon-core thread pool, rather than direct use by end users.
44
5-
use std::fmt;
65
use latch::LatchProbe;
76
use registry;
7+
use std::fmt;
88

99
/// Represents the active worker thread.
1010
pub struct WorkerThread<'w> {
11-
thread: &'w registry::WorkerThread
11+
thread: &'w registry::WorkerThread,
1212
}
1313

1414
impl<'w> WorkerThread<'w> {
@@ -25,8 +25,13 @@ impl<'w> WorkerThread<'w> {
2525
/// you must ensure that, once the condition `f()` becomes true,
2626
/// some "rayon event" will also occur to ensure that waiting
2727
/// threads are awoken.
28-
pub unsafe fn wait_until_true<F>(&self, f: F) where F: Fn() -> bool {
29-
struct DummyLatch<'a, F: 'a> { f: &'a F }
28+
pub unsafe fn wait_until_true<F>(&self, f: F)
29+
where
30+
F: Fn() -> bool,
31+
{
32+
struct DummyLatch<'a, F: 'a> {
33+
f: &'a F,
34+
}
3035

3136
impl<'a, F: Fn() -> bool> LatchProbe for DummyLatch<'a, F> {
3237
fn probe(&self) -> bool {
@@ -51,17 +56,19 @@ impl<'w> fmt::Debug for WorkerThread<'w> {
5156
/// is invoked with a reference to the worker-thread the result of
5257
/// that callback is returned with `Some`. Otherwise, if we are not on
5358
/// a Rayon worker thread, `None` is immediately returned.
54-
pub fn if_in_worker_thread<F,R>(if_true: F) -> Option<R>
55-
where F: FnOnce(&WorkerThread) -> R,
59+
pub fn if_in_worker_thread<F, R>(if_true: F) -> Option<R>
60+
where
61+
F: FnOnce(&WorkerThread) -> R,
5662
{
5763
let worker_thread = registry::WorkerThread::current();
5864
if worker_thread.is_null() {
5965
None
6066
} else {
6167
unsafe {
62-
let wt = WorkerThread { thread: &*worker_thread };
68+
let wt = WorkerThread {
69+
thread: &*worker_thread,
70+
};
6371
Some(if_true(&wt))
6472
}
6573
}
6674
}
67-

rayon-core/src/job.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ impl JobRef {
4141
/// Unsafe: caller asserts that `data` will remain valid until the
4242
/// job is executed.
4343
pub unsafe fn new<T>(data: *const T) -> JobRef
44-
where T: Job
44+
where
45+
T: Job,
4546
{
4647
let fn_ptr: unsafe fn(*const T) = <T as Job>::execute;
4748

@@ -66,19 +67,21 @@ impl JobRef {
6667
/// the stack frame is later popped. The function parameter indicates
6768
/// `true` if the job was stolen -- executed on a different thread.
6869
pub struct StackJob<L, F, R>
69-
where L: Latch + Sync,
70-
F: FnOnce(bool) -> R + Send,
71-
R: Send
70+
where
71+
L: Latch + Sync,
72+
F: FnOnce(bool) -> R + Send,
73+
R: Send,
7274
{
7375
pub latch: L,
7476
func: UnsafeCell<Option<F>>,
7577
result: UnsafeCell<JobResult<R>>,
7678
}
7779

7880
impl<L, F, R> StackJob<L, F, R>
79-
where L: Latch + Sync,
80-
F: FnOnce(bool) -> R + Send,
81-
R: Send
81+
where
82+
L: Latch + Sync,
83+
F: FnOnce(bool) -> R + Send,
84+
R: Send,
8285
{
8386
pub fn new(func: F, latch: L) -> StackJob<L, F, R> {
8487
StackJob {
@@ -102,9 +105,10 @@ impl<L, F, R> StackJob<L, F, R>
102105
}
103106

104107
impl<L, F, R> Job for StackJob<L, F, R>
105-
where L: Latch + Sync,
106-
F: FnOnce(bool) -> R + Send,
107-
R: Send
108+
where
109+
L: Latch + Sync,
110+
F: FnOnce(bool) -> R + Send,
111+
R: Send,
108112
{
109113
unsafe fn execute(this: *const Self) {
110114
let this = &*this;
@@ -126,16 +130,20 @@ impl<L, F, R> Job for StackJob<L, F, R>
126130
///
127131
/// (Probably `StackJob` should be refactored in a similar fashion.)
128132
pub struct HeapJob<BODY>
129-
where BODY: FnOnce() + Send
133+
where
134+
BODY: FnOnce() + Send,
130135
{
131136
job: UnsafeCell<Option<BODY>>,
132137
}
133138

134139
impl<BODY> HeapJob<BODY>
135-
where BODY: FnOnce() + Send
140+
where
141+
BODY: FnOnce() + Send,
136142
{
137143
pub fn new(func: BODY) -> Self {
138-
HeapJob { job: UnsafeCell::new(Some(func)) }
144+
HeapJob {
145+
job: UnsafeCell::new(Some(func)),
146+
}
139147
}
140148

141149
/// Creates a `JobRef` from this job -- note that this hides all
@@ -148,7 +156,8 @@ impl<BODY> HeapJob<BODY>
148156
}
149157

150158
impl<BODY> Job for HeapJob<BODY>
151-
where BODY: FnOnce() + Send
159+
where
160+
BODY: FnOnce() + Send,
152161
{
153162
unsafe fn execute(this: *const Self) {
154163
let this: Box<Self> = mem::transmute(this);

rayon-core/src/join/mod.rs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use job::StackJob;
12
use latch::{LatchProbe, SpinLatch};
23
use log::Event::*;
3-
use job::StackJob;
44
use registry::{self, WorkerThread};
55
use std::any::Any;
66
use unwind;
@@ -92,10 +92,11 @@ mod test;
9292
/// panic with the same panic value. If both closures panic, `join()`
9393
/// will panic with the panic value from the first closure.
9494
pub fn join<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB)
95-
where A: FnOnce() -> RA + Send,
96-
B: FnOnce() -> RB + Send,
97-
RA: Send,
98-
RB: Send
95+
where
96+
A: FnOnce() -> RA + Send,
97+
B: FnOnce() -> RB + Send,
98+
RA: Send,
99+
RB: Send,
99100
{
100101
join_context(|_| oper_a(), |_| oper_b())
101102
}
@@ -108,19 +109,24 @@ pub fn join<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB)
108109
/// `join_context` was called from outside the thread pool to begin
109110
/// with.
110111
pub fn join_context<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB)
111-
where A: FnOnce(FnContext) -> RA + Send,
112-
B: FnOnce(FnContext) -> RB + Send,
113-
RA: Send,
114-
RB: Send
112+
where
113+
A: FnOnce(FnContext) -> RA + Send,
114+
B: FnOnce(FnContext) -> RB + Send,
115+
RA: Send,
116+
RB: Send,
115117
{
116118
registry::in_worker(|worker_thread, injected| unsafe {
117-
log!(Join { worker: worker_thread.index() });
119+
log!(Join {
120+
worker: worker_thread.index()
121+
});
118122

119123
// Create virtual wrapper for task b; this all has to be
120124
// done here so that the stack frame can keep it all live
121125
// long enough.
122-
let job_b = StackJob::new(|migrated| oper_b(FnContext::new(migrated)),
123-
SpinLatch::new());
126+
let job_b = StackJob::new(
127+
|migrated| oper_b(FnContext::new(migrated)),
128+
SpinLatch::new(),
129+
);
124130
let job_b_ref = job_b.as_job_ref();
125131
worker_thread.push(job_b_ref);
126132

@@ -142,17 +148,23 @@ pub fn join_context<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB)
142148
// Found it! Let's run it.
143149
//
144150
// Note that this could panic, but it's ok if we unwind here.
145-
log!(PoppedRhs { worker: worker_thread.index() });
151+
log!(PoppedRhs {
152+
worker: worker_thread.index()
153+
});
146154
let result_b = job_b.run_inline(injected);
147155
return (result_a, result_b);
148156
} else {
149-
log!(PoppedJob { worker: worker_thread.index() });
157+
log!(PoppedJob {
158+
worker: worker_thread.index()
159+
});
150160
worker_thread.execute(job);
151161
}
152162
} else {
153163
// Local deque is empty. Time to steal from other
154164
// threads.
155-
log!(LostJob { worker: worker_thread.index() });
165+
log!(LostJob {
166+
worker: worker_thread.index()
167+
});
156168
worker_thread.wait_until(&job_b.latch);
157169
debug_assert!(job_b.latch.probe());
158170
break;
@@ -167,11 +179,11 @@ pub fn join_context<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB)
167179
/// B is complete. This is because it may contain references into the
168180
/// enclosing stack frame(s).
169181
#[cold] // cold path
170-
unsafe fn join_recover_from_panic(worker_thread: &WorkerThread,
171-
job_b_latch: &SpinLatch,
172-
err: Box<Any + Send>)
173-
-> !
174-
{
182+
unsafe fn join_recover_from_panic(
183+
worker_thread: &WorkerThread,
184+
job_b_latch: &SpinLatch,
185+
err: Box<Any + Send>,
186+
) -> ! {
175187
worker_thread.wait_until(job_b_latch);
176188
unwind::resume_unwinding(err)
177189
}

rayon-core/src/join/test.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Tests for the join code.
22
3-
use ThreadPoolBuilder;
43
use join::*;
5-
use rand::{Rng, SeedableRng, XorShiftRng};
64
use rand::distributions::Standard;
5+
use rand::{Rng, SeedableRng, XorShiftRng};
76
use unwind;
7+
use ThreadPoolBuilder;
88

99
fn quick_sort<T: PartialOrd + Send>(v: &mut [T]) {
1010
if v.len() <= 1 {
@@ -96,9 +96,8 @@ fn join_context_both() {
9696
fn join_context_neither() {
9797
// If we're already in a 1-thread pool, neither job should be stolen.
9898
let pool = ThreadPoolBuilder::new().num_threads(1).build().unwrap();
99-
let (a_migrated, b_migrated) = pool.install(|| {
100-
join_context(|a| a.migrated(), |b| b.migrated())
101-
});
99+
let (a_migrated, b_migrated) =
100+
pool.install(|| join_context(|a| a.migrated(), |b| b.migrated()));
102101
assert!(!a_migrated);
103102
assert!(!b_migrated);
104103
}
@@ -111,8 +110,16 @@ fn join_context_second() {
111110
let barrier = Barrier::new(2);
112111
let pool = ThreadPoolBuilder::new().num_threads(2).build().unwrap();
113112
let (a_migrated, b_migrated) = pool.install(|| {
114-
join_context(|a| { barrier.wait(); a.migrated() },
115-
|b| { barrier.wait(); b.migrated() })
113+
join_context(
114+
|a| {
115+
barrier.wait();
116+
a.migrated()
117+
},
118+
|b| {
119+
barrier.wait();
120+
b.migrated()
121+
},
122+
)
116123
});
117124
assert!(!a_migrated);
118125
assert!(b_migrated);

rayon-core/src/latch.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
2-
use std::sync::{Mutex, Condvar};
2+
use std::sync::{Condvar, Mutex};
33
use std::usize;
44

55
use sleep::Sleep;
@@ -50,7 +50,9 @@ pub struct SpinLatch {
5050
impl SpinLatch {
5151
#[inline]
5252
pub fn new() -> SpinLatch {
53-
SpinLatch { b: AtomicBool::new(false) }
53+
SpinLatch {
54+
b: AtomicBool::new(false),
55+
}
5456
}
5557
}
5658

@@ -124,7 +126,9 @@ pub struct CountLatch {
124126
impl CountLatch {
125127
#[inline]
126128
pub fn new() -> CountLatch {
127-
CountLatch { counter: AtomicUsize::new(1) }
129+
CountLatch {
130+
counter: AtomicUsize::new(1),
131+
}
128132
}
129133

130134
#[inline]
@@ -150,7 +154,6 @@ impl Latch for CountLatch {
150154
}
151155
}
152156

153-
154157
/// A tickling latch wraps another latch type, and will also awaken a thread
155158
/// pool when it is set. This is useful for jobs injected between thread pools,
156159
/// so the source pool can continue processing its own work while waiting.

0 commit comments

Comments
 (0)