about summary refs log tree commit diff
path: root/src/libstd/sync/mpsc/mpsc_queue.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-11-30 12:42:44 +0000
committerbors <bors@rust-lang.org>2019-11-30 12:42:44 +0000
commitd8bdb3fdcbd88eb16e1a6669236122c41ed2aed3 (patch)
tree33974ee0e3d5976f284b056e03e6ef529d15e563 /src/libstd/sync/mpsc/mpsc_queue.rs
parent8f1bbd69e13c9e04a4c2b75612bc0c31af972439 (diff)
parentb14d9c21203ea79035bf4a8a8a68ad34658a265f (diff)
downloadrust-d8bdb3fdcbd88eb16e1a6669236122c41ed2aed3.tar.gz
rust-d8bdb3fdcbd88eb16e1a6669236122c41ed2aed3.zip
Auto merge of #66887 - dtolnay:rollup-uxowp8d, r=Centril
Rollup of 4 pull requests

Successful merges:

 - #66818 (Format libstd/os with rustfmt)
 - #66819 (Format libstd/sys with rustfmt)
 - #66820 (Format libstd with rustfmt)
 - #66847 (Allow any identifier as format arg name)

Failed merges:

r? @ghost
Diffstat (limited to 'src/libstd/sync/mpsc/mpsc_queue.rs')
-rw-r--r--src/libstd/sync/mpsc/mpsc_queue.rs28
1 files changed, 11 insertions, 17 deletions
diff --git a/src/libstd/sync/mpsc/mpsc_queue.rs b/src/libstd/sync/mpsc/mpsc_queue.rs
index 8f5681b97f4..6e7a7be4430 100644
--- a/src/libstd/sync/mpsc/mpsc_queue.rs
+++ b/src/libstd/sync/mpsc/mpsc_queue.rs
@@ -13,8 +13,8 @@
 
 pub use self::PopResult::*;
 
-use core::ptr;
 use core::cell::UnsafeCell;
+use core::ptr;
 
 use crate::boxed::Box;
 use crate::sync::atomic::{AtomicPtr, Ordering};
@@ -45,15 +45,12 @@ pub struct Queue<T> {
     tail: UnsafeCell<*mut Node<T>>,
 }
 
-unsafe impl<T: Send> Send for Queue<T> { }
-unsafe impl<T: Send> Sync for Queue<T> { }
+unsafe impl<T: Send> Send for Queue<T> {}
+unsafe impl<T: Send> Sync for Queue<T> {}
 
 impl<T> Node<T> {
     unsafe fn new(v: Option<T>) -> *mut Node<T> {
-        Box::into_raw(box Node {
-            next: AtomicPtr::new(ptr::null_mut()),
-            value: v,
-        })
+        Box::into_raw(box Node { next: AtomicPtr::new(ptr::null_mut()), value: v })
     }
 }
 
@@ -62,10 +59,7 @@ impl<T> Queue<T> {
     /// one consumer.
     pub fn new() -> Queue<T> {
         let stub = unsafe { Node::new(None) };
-        Queue {
-            head: AtomicPtr::new(stub),
-            tail: UnsafeCell::new(stub),
-        }
+        Queue { head: AtomicPtr::new(stub), tail: UnsafeCell::new(stub) }
     }
 
     /// Pushes a new value onto this queue.
@@ -101,7 +95,7 @@ impl<T> Queue<T> {
                 return Data(ret);
             }
 
-            if self.head.load(Ordering::Acquire) == tail {Empty} else {Inconsistent}
+            if self.head.load(Ordering::Acquire) == tail { Empty } else { Inconsistent }
         }
     }
 }
@@ -121,7 +115,7 @@ impl<T> Drop for Queue<T> {
 
 #[cfg(all(test, not(target_os = "emscripten")))]
 mod tests {
-    use super::{Queue, Data, Empty, Inconsistent};
+    use super::{Data, Empty, Inconsistent, Queue};
     use crate::sync::mpsc::channel;
     use crate::sync::Arc;
     use crate::thread;
@@ -140,7 +134,7 @@ mod tests {
         let q = Queue::new();
         match q.pop() {
             Empty => {}
-            Inconsistent | Data(..) => panic!()
+            Inconsistent | Data(..) => panic!(),
         }
         let (tx, rx) = channel();
         let q = Arc::new(q);
@@ -148,7 +142,7 @@ mod tests {
         for _ in 0..nthreads {
             let tx = tx.clone();
             let q = q.clone();
-            thread::spawn(move|| {
+            thread::spawn(move || {
                 for i in 0..nmsgs {
                     q.push(i);
                 }
@@ -159,8 +153,8 @@ mod tests {
         let mut i = 0;
         while i < nthreads * nmsgs {
             match q.pop() {
-                Empty | Inconsistent => {},
-                Data(_) => { i += 1 }
+                Empty | Inconsistent => {}
+                Data(_) => i += 1,
             }
         }
         drop(tx);