Skip to content

Commit f6e30f5

Browse files
committed
Rustfmt
1 parent 3d50312 commit f6e30f5

File tree

5 files changed

+42
-26
lines changed

5 files changed

+42
-26
lines changed

crossbeam-circbuf/src/buffer.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::cell::UnsafeCell;
2+
use std::mem;
23
use std::sync::atomic::AtomicUsize;
34
use std::sync::atomic::Ordering;
4-
use std::mem;
55

66
/// A slot in buffer.
77
#[derive(Debug)]
@@ -60,7 +60,7 @@ impl<T> Buffer<T> {
6060

6161
impl<T> Drop for Buffer<T> {
6262
fn drop(&mut self) {
63-
unsafe {
63+
unsafe {
6464
drop(Vec::from_raw_parts(self.ptr, 0, self.cap));
6565
}
6666
}
@@ -110,7 +110,10 @@ impl<T> Buffer<T> {
110110
let slot = self.at(index);
111111

112112
// Writes the value.
113-
(*slot).data.get().write_volatile(mem::ManuallyDrop::new(value));
113+
(*slot)
114+
.data
115+
.get()
116+
.write_volatile(mem::ManuallyDrop::new(value));
114117

115118
// Writes the index with `Release`.
116119
(*slot).index.store(index, Ordering::Release);

crossbeam-circbuf/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ extern crate crossbeam_utils as utils;
1212

1313
mod buffer;
1414

15-
#[doc(hidden)] // for doc-tests
16-
pub mod sp;
1715
#[doc(hidden)] // for doc-tests
1816
pub mod mp;
17+
#[doc(hidden)] // for doc-tests
18+
pub mod sp;
1919

20+
pub use mp::mc as mpmc;
2021
pub use sp::mc as spmc;
2122
pub use sp::sc as spsc;
22-
pub use mp::mc as mpmc;
2323

2424
/// The return type for `try_recv` methods.
2525
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

crossbeam-circbuf/src/mp/mc.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
/// assert_eq!(r.recv(), Some('b'));
2525
/// ```
2626
pub mod bounded {
27-
use std::sync::atomic::Ordering;
28-
use std::sync::atomic::AtomicUsize;
2927
use std::marker::PhantomData;
3028
use std::mem::ManuallyDrop;
29+
use std::sync::atomic::AtomicUsize;
30+
use std::sync::atomic::Ordering;
3131
use utils::CachePadded;
3232

3333
use buffer::Buffer;
@@ -135,7 +135,7 @@ pub mod bounded {
135135
unsafe { self.buffer.write(index.wrapping_add(self.lap()), value) };
136136
return Ok(());
137137
}
138-
// But if the slot lags one lap behind the tail...
138+
// But if the slot lags one lap behind the tail...
139139
} else if index.wrapping_add(self.lap()) == tail {
140140
let head = self.head.load(Ordering::Acquire);
141141

@@ -179,7 +179,10 @@ pub mod bounded {
179179
{
180180
// Reads the value from the slot and update the stamp.
181181
let value = unsafe { self.buffer.read_value(index) };
182-
unsafe { self.buffer.write_index(index.wrapping_add(self.lap()), Ordering::Release) };
182+
unsafe {
183+
self.buffer
184+
.write_index(index.wrapping_add(self.lap()), Ordering::Release)
185+
};
183186
return Some(ManuallyDrop::into_inner(value));
184187
}
185188
// But if the slot lags one lap behind the head...
@@ -194,7 +197,7 @@ pub mod bounded {
194197
}
195198
}
196199
}
197-
200+
198201
/// Returns `true` if the queue is empty.
199202
///
200203
/// Inaccurate in the presence of concurrent method invocations.
@@ -208,21 +211,21 @@ pub mod bounded {
208211
// when the queue was not empty, so it is safe to just return `false`.
209212
tail.wrapping_add(self.lap()) == head
210213
}
211-
214+
212215
/// Returns `true` if the queue is full.
213216
///
214217
/// Inaccurate in the presence of concurrent method invocations.
215218
pub fn is_full(&self) -> bool {
216219
let tail = self.tail.load(Ordering::Relaxed);
217220
let head = self.head.load(Ordering::Relaxed);
218-
221+
219222
// Is the head lagging one lap behind tail?
220223
//
221224
// Note: If the tail changes just before we load the head, that means there was a moment
222225
// when the queue was not full, so it is safe to just return `false`.
223226
head.wrapping_add(self.lap()) == tail
224227
}
225-
228+
226229
/// Returns the current number of elements inside the queue.
227230
///
228231
/// Inaccurate in the presence of concurrent method invocations.
@@ -233,7 +236,7 @@ pub mod bounded {
233236

234237
let hix = head & (self.lap() - 1);
235238
let tix = tail & (self.lap() - 1);
236-
239+
237240
if hix < tix {
238241
tix - hix
239242
} else if hix > tix {
@@ -250,7 +253,7 @@ pub mod bounded {
250253
fn drop(&mut self) {
251254
// Get the index of the head.
252255
let hix = self.head.load(Ordering::Relaxed) & (self.lap() - 1);
253-
256+
254257
// Loop over all slots that hold a message and drop them.
255258
for i in 0..self.len() {
256259
// Compute the index of the next slot holding a message.

crossbeam-circbuf/src/sp/internal.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,8 @@ impl<T> Receiver<T> {
677677
rx.wrapping_add(num),
678678
Ordering::Release,
679679
Ordering::Relaxed,
680-
).is_err()
680+
)
681+
.is_err()
681682
{
682683
// We didn't receive the values.
683684
return TryRecv::Retry;
@@ -886,7 +887,8 @@ mod tests {
886887
}
887888
}
888889
})
889-
}).collect::<Vec<_>>();
890+
})
891+
.collect::<Vec<_>>();
890892

891893
while remaining.load(SeqCst) > 0 {
892894
if let TryRecv::Data(_) = cb.try_recv() {
@@ -919,7 +921,8 @@ mod tests {
919921
}
920922
}
921923
})
922-
}).collect::<Vec<_>>();
924+
})
925+
.collect::<Vec<_>>();
923926

924927
let mut rng = rand::thread_rng();
925928
let mut expected = 0;
@@ -982,7 +985,8 @@ mod tests {
982985
};
983986

984987
(t, hits)
985-
}).unzip();
988+
})
989+
.unzip();
986990

987991
let mut rng = rand::thread_rng();
988992
let mut my_hits = 0;
@@ -1040,7 +1044,8 @@ mod tests {
10401044
}
10411045
}
10421046
})
1043-
}).collect::<Vec<_>>();
1047+
})
1048+
.collect::<Vec<_>>();
10441049

10451050
for _ in 0..1000 {
10461051
if let TryRecv::Data(_) = cb.try_recv() {

crossbeam-circbuf/tests/mpmc_bounded.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ fn len() {
108108
assert!(len <= CAP);
109109
}
110110
});
111-
}).unwrap();
111+
})
112+
.unwrap();
112113
assert_eq!(q.len(), 0);
113114
}
114115

@@ -136,7 +137,8 @@ fn spsc() {
136137
while q.send(i).is_err() {}
137138
}
138139
});
139-
}).unwrap();
140+
})
141+
.unwrap();
140142
}
141143

142144
#[test]
@@ -167,7 +169,8 @@ fn mpmc() {
167169
}
168170
});
169171
}
170-
}).unwrap();
172+
})
173+
.unwrap();
171174

172175
for c in v {
173176
assert_eq!(c.load(Ordering::SeqCst), THREADS);
@@ -212,7 +215,8 @@ fn drops() {
212215
}
213216
}
214217
});
215-
}).unwrap();
218+
})
219+
.unwrap();
216220

217221
for _ in 0..additional {
218222
q.send(DropCounter).unwrap();
@@ -240,5 +244,6 @@ fn linearizable() {
240244
}
241245
});
242246
}
243-
}).unwrap();
247+
})
248+
.unwrap();
244249
}

0 commit comments

Comments
 (0)