todo comment

serial
Avril 3 years ago
parent 5fcb1fd6c3
commit 0a4d055fff
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -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.
}

@ -44,14 +44,14 @@ fn spawn_for_lazy(recv: state::PendingReceiver<Job>) -> impl Iterator<Item = Joi
}
/// Spawn the thread pool and return handles to the spawned threads as a `Pool`.
#[inline] pub fn spawn_for_pool(recv: state::PendingReceiver<Job>) -> Pool
#[inline] fn spawn_for_pool(recv: state::PendingReceiver<Job>) -> 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<Job>)
{
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<Job>) -> Pool
{
spawn_for_pool(recv)
}

@ -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<usize, Box<dyn std::error::Error>>
pub fn work_on(job: &mut Job) -> io::Result<usize>
{
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..])? {

Loading…
Cancel
Save