From 0a4d055fffa81db63f186cb2883b1eadfaccc8e5 Mon Sep 17 00:00:00 2001 From: Avril Date: Mon, 28 Dec 2020 00:32:42 +0000 Subject: [PATCH] todo comment --- src/main.rs | 12 ++++++++++-- src/pool.rs | 13 +++++++++++-- src/work.rs | 7 ++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2061037..cb6298f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,8 +8,16 @@ mod work; mod consts; -pub const BUFSIZE: usize = 4096; // 4kb - fn main() { println!("Hello, world!"); + // todo: + // - create and open output file + // - open and stat all input files (`job::create_from_file`). + // - `fallocate` the output file fd to the sum of all input file sizes + // - `mmap` the output file as writable + // + // - spawn the task thread pool + // - dispatch jobs with their fds, stats, and calculated output offsets along with a reference to the output mapped file (`job::Prelude::start`) + // - wait on all worker threads to complete. + // - ensure all data was written. } diff --git a/src/pool.rs b/src/pool.rs index 155c6b5..bc554f8 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -44,14 +44,14 @@ fn spawn_for_lazy(recv: state::PendingReceiver) -> impl Iterator) -> Pool +#[inline] fn spawn_for_pool(recv: state::PendingReceiver) -> Pool { spawn_for_lazy(recv).collect() } /// Spawn and then immediately wait on a thread pool to complete. /// -/// Has the same behaviour as `drop(spawn_for_pool(recv))` but skips a heap allocation. +/// Has the same behaviour as `drop(spawn_for_pool(recv))` but skips a potential heap allocation. #[inline] pub fn spawn_for_and_join(recv: state::PendingReceiver) { join_all(spawn_for_lazy(recv)); @@ -125,3 +125,12 @@ impl Drop for Pool } } } + +/// Spawn a thread pool. +/// +/// The pool can be spawned in different ways, this uses the default one. +/// The others are not made public except [`spawn_for_and_join`], as their behaviour differences are very subtle. +#[inline(always)] pub fn pool(recv: state::PendingReceiver) -> Pool +{ + spawn_for_pool(recv) +} diff --git a/src/work.rs b/src/work.rs index e362c80..809796e 100644 --- a/src/work.rs +++ b/src/work.rs @@ -1,14 +1,15 @@ use super::*; use job::Job; -use std::io::Read; +use std::io::{self, Read}; -pub fn work_on(job: &mut Job) -> Result> +pub fn work_on(job: &mut Job) -> io::Result { let output = job.output_slice(); let output = unsafe { - // Required because the compiler thinks we're mutably borrowing the same data later on, even though they are unrelated fields of the struct + // SAFETY: Required because the compiler thinks we're mutably borrowing the same data later on, even though they are unrelated fields of the struct std::slice::from_raw_parts_mut(output.as_mut_ptr(), output.len()) }; + let mut read=0; while read < job.len() { match job.read(&mut output[read..])? {