diff --git a/src/main.rs b/src/main.rs index b1045ff..91ee20a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -79,17 +79,24 @@ fn work(arg::Operation{output, inputs}: arg::Operation) -> Result<(), Box, - completion: mpsc::Sender<(usize, usize)>, + completion: Mutex>, } // SAFETY: The whole point of this is internal mutablility across thread boundaries. @@ -29,13 +29,13 @@ impl State /// Create a new state from this map #[inline] pub fn new(map: super::map::MemoryMapMut, completion: mpsc::Sender<(usize, usize)>) -> Self { - Self(Arc::new(StateInner{map: UnsafeCell::new(map), completion})) + Self(Arc::new(StateInner{map: UnsafeCell::new(map), completion: Mutex::new(completion)})) } /// Send a completion signal for the file of this index and this size. pub fn send_complete(&self, idx: usize, size: usize) -> Result<(), mpsc::SendError<(usize, usize)>> { - self.0.completion.send((idx, size)) + self.0.completion.lock().unwrap().send((idx, size)) } /// Try to consume this instance into its map. This will only succeed if there are no more references to the state than this one. diff --git a/src/work.rs b/src/work.rs index 809796e..7faa508 100644 --- a/src/work.rs +++ b/src/work.rs @@ -1,6 +1,7 @@ use super::*; use job::Job; use std::io::{self, Read}; +use std::fmt; pub fn work_on(job: &mut Job) -> io::Result { @@ -19,3 +20,21 @@ pub fn work_on(job: &mut Job) -> io::Result } Ok(read) } + +pub fn output_if_able(ar: &mut T) +where T: AsMut<[job::Status]> + ?Sized, + D: fmt::Display +{ + let slice = ar.as_mut(); + for item in slice.iter_mut() + { + if item.is_pending() { + return + } else { + if let Some(item) = item.take() { + println!("{}", item); + } + } + } +} +