]> git.proxmox.com Git - proxmox-backup.git/blobdiff - src/tools/parallel_handler.rs
typo fixes all over the place
[proxmox-backup.git] / src / tools / parallel_handler.rs
index 36a7b8590ccef9718a2ba033208ecc5836944544..76f761c4e3e3c54f88e16b60ccbfbe8e8fb8ed2b 100644 (file)
@@ -38,11 +38,10 @@ impl<I: Send> SendHandle<I> {
 ///
 /// When done, the 'complete()' method needs to be called to check for
 /// outstanding errors.
-pub struct ParallelHandler<'a, I> {
+pub struct ParallelHandler<I> {
     handles: Vec<JoinHandle<()>>,
     name: String,
     input: Option<SendHandle<I>>,
-    _marker: std::marker::PhantomData<&'a ()>,
 }
 
 impl<I> Clone for SendHandle<I> {
@@ -54,11 +53,11 @@ impl<I> Clone for SendHandle<I> {
     }
 }
 
-impl<'a, I: Send + 'static> ParallelHandler<'a, I> {
+impl<I: Send + 'static> ParallelHandler<I> {
     /// Create a new thread pool, each thread processing incoming data
     /// with 'handler_fn'.
     pub fn new<F>(name: &str, threads: usize, handler_fn: F) -> Self
-        where F: Fn(I) -> Result<(), Error> + Send + Clone + 'a,
+        where F: Fn(I) -> Result<(), Error> + Send + Clone + 'static,
     {
         let mut handles = Vec::new();
         let (input_tx, input_rx) = bounded::<I>(threads);
@@ -68,13 +67,7 @@ impl<'a, I: Send + 'static> ParallelHandler<'a, I> {
         for i in 0..threads {
             let input_rx = input_rx.clone();
             let abort = Arc::clone(&abort);
-
-            // Erase the 'a lifetime bound. This is safe because we
-            // join all thread in the drop handler.
-            let handler_fn: Box<dyn Fn(I) -> Result<(), Error> + Send + 'a> =
-                Box::new(handler_fn.clone());
-            let handler_fn: Box<dyn Fn(I) -> Result<(), Error> + Send + 'static> =
-                unsafe { std::mem::transmute(handler_fn) };
+            let handler_fn = handler_fn.clone();
 
             handles.push(
                 std::thread::Builder::new()
@@ -104,7 +97,6 @@ impl<'a, I: Send + 'static> ParallelHandler<'a, I> {
                 input: input_tx,
                 abort,
             }),
-            _marker: std::marker::PhantomData,
         }
     }
 
@@ -142,18 +134,14 @@ impl<'a, I: Send + 'static> ParallelHandler<'a, I> {
         let mut msg_list = Vec::new();
 
         let mut i = 0;
-        loop {
-            let handle = match self.handles.pop() {
-                Some(handle) => handle,
-                None => break,
-            };
+        while let Some(handle) = self.handles.pop() {
             if let Err(panic) = handle.join() {
                 match panic.downcast::<&str>() {
                     Ok(panic_msg) => msg_list.push(
-                        format!("thread {} ({}) paniced: {}", self.name, i, panic_msg)
+                        format!("thread {} ({}) panicked: {}", self.name, i, panic_msg)
                     ),
                     Err(_) => msg_list.push(
-                        format!("thread {} ({}) paniced", self.name, i)
+                        format!("thread {} ({}) panicked", self.name, i)
                     ),
                 }
             }
@@ -164,7 +152,7 @@ impl<'a, I: Send + 'static> ParallelHandler<'a, I> {
 }
 
 // Note: We make sure that all threads will be joined
-impl<'a, I> Drop for ParallelHandler<'a, I> {
+impl<I> Drop for ParallelHandler<I> {
     fn drop(&mut self) {
         drop(self.input.take());
         while let Some(handle) = self.handles.pop() {