Skip to content

Commit

Permalink
Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
vertexclique committed Oct 20, 2019
1 parent 22367c8 commit 929b1e9
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 38 deletions.
10 changes: 5 additions & 5 deletions lightproc/examples/proc_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use lightproc::prelude::*;
use std::sync::atomic::AtomicUsize;

fn spawn_on_thread<F, R>(fut: F) -> ProcHandle<R>
where
F: Future<Output = R> + Send + 'static,
R: Send + 'static,
where
F: Future<Output = R> + Send + 'static,
R: Send + 'static,
{
let (sender, receiver) = channel::unbounded();
let sender = Arc::new(sender);
Expand All @@ -34,8 +34,8 @@ fn spawn_on_thread<F, R>(fut: F) -> ProcHandle<R>
})),
before_start: Some(Arc::new(|| {
println!("Before start");
}))
}
})),
},
);

proc.schedule();
Expand Down
5 changes: 1 addition & 4 deletions lightproc/src/layout_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ pub fn extend(layout: Layout, next: Layout) -> (Layout, usize) {
.unwrap();
let new_size = offset
.checked_add(next.size())
.ok_or(Error::new(
ErrorKind::Other,
"New size can't be computed",
))
.ok_or(Error::new(ErrorKind::Other, "New size can't be computed"))
.unwrap();

let layout = Layout::from_size_align(new_size, new_align).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions lightproc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ pub mod lightproc;
pub mod proc_data;
pub mod proc_handle;
pub mod proc_layout;
pub mod proc_stack;
pub mod proc_vtable;
pub mod raw_proc;
pub mod proc_stack;
pub mod state;

pub mod prelude {
pub use crate::lightproc::*;
pub use crate::proc_stack::*;
pub use crate::proc_handle::*;
pub use crate::proc_stack::*;
}
15 changes: 6 additions & 9 deletions lightproc/src/lightproc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use std::mem;
use std::ptr::NonNull;

use crate::proc_data::ProcData;
use crate::raw_proc::RawProc;
use crate::proc_handle::ProcHandle;
use crate::proc_stack::*;

use crate::raw_proc::RawProc;

pub struct LightProc {
/// A pointer to the heap-allocated task.
Expand All @@ -20,15 +19,13 @@ unsafe impl Sync for LightProc {}

impl LightProc {
pub fn build<F, R, S>(future: F, schedule: S, stack: ProcStack) -> (LightProc, ProcHandle<R>)
where
F: Future<Output = R> + Send + 'static,
R: Send + 'static,
S: Fn(LightProc) + Send + Sync + 'static
where
F: Future<Output = R> + Send + 'static,
R: Send + 'static,
S: Fn(LightProc) + Send + Sync + 'static,
{
let raw_task = RawProc::<F, R, S>::allocate(stack, future, schedule);
let task = LightProc {
raw_proc: raw_task
};
let task = LightProc { raw_proc: raw_task };
let handle = ProcHandle {
raw_proc: raw_task,
_marker: PhantomData,
Expand Down
4 changes: 2 additions & 2 deletions lightproc/src/proc_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::task::Waker;

use crossbeam_utils::Backoff;

use crate::state::*;
use crate::layout_helpers::extend;
use crate::proc_stack::*;
use crate::proc_vtable::TaskVTable;
use crate::layout_helpers::extend;
use crate::state::*;

/// The pdata of a task.
///
Expand Down
7 changes: 3 additions & 4 deletions lightproc/src/proc_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use std::ptr::NonNull;
use std::sync::atomic::Ordering;
use std::task::{Context, Poll};

use crate::state::*;
use crate::proc_stack::*;
use crate::proc_data::ProcData;
use crate::proc_stack::*;
use crate::state::*;

/// A handle that awaits the result of a task.
///
Expand Down Expand Up @@ -125,8 +125,7 @@ impl<R> Drop for ProcHandle<R> {
) {
Ok(_) => {
// Read the output.
output =
Some((((*pdata).vtable.get_output)(ptr) as *mut R).read());
output = Some((((*pdata).vtable.get_output)(ptr) as *mut R).read());

// Update the state variable because we're continuing the loop.
state |= CLOSED;
Expand Down
4 changes: 2 additions & 2 deletions lightproc/src/proc_stack.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt;
use std::fmt::{Error, Formatter};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::fmt::{Formatter, Error};
use std::fmt;

#[derive(Default)]
pub struct ProcStack {
Expand Down
20 changes: 10 additions & 10 deletions lightproc/src/raw_proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use std::ptr::NonNull;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};

use crate::state::*;
use crate::layout_helpers::extend;
use crate::lightproc::LightProc;
use crate::proc_data::ProcData;
use crate::proc_layout::TaskLayout;
use crate::proc_stack::*;
use crate::proc_vtable::TaskVTable;
use crate::proc_layout::TaskLayout;
use crate::proc_data::ProcData;
use crate::lightproc::LightProc;
use crate::layout_helpers::extend;
use crate::state::*;

/// Raw pointers to the fields of a task.
pub(crate) struct RawProc<F, R, S> {
Expand Down Expand Up @@ -42,7 +42,7 @@ impl<F, R, S> RawProc<F, R, S>
where
F: Future<Output = R> + Send + 'static,
R: Send + 'static,
S: Fn(LightProc) + Send + Sync + 'static
S: Fn(LightProc) + Send + Sync + 'static,
{
/// Allocates a task with the given `future` and `schedule` function.
///
Expand Down Expand Up @@ -184,7 +184,7 @@ where
if state & (SCHEDULED | RUNNING) == 0 {
// Schedule the task.
let task = LightProc {
raw_proc: NonNull::new_unchecked(ptr as *mut ())
raw_proc: NonNull::new_unchecked(ptr as *mut ()),
};
(*raw.schedule)(task);
} else {
Expand Down Expand Up @@ -250,7 +250,7 @@ where

// Schedule the task.
let task = LightProc {
raw_proc: NonNull::new_unchecked(ptr as *mut ())
raw_proc: NonNull::new_unchecked(ptr as *mut ()),
};
(*raw.schedule)(task);
}
Expand Down Expand Up @@ -306,7 +306,7 @@ where
let raw = Self::from_ptr(ptr);

(*raw.schedule)(LightProc {
raw_proc: NonNull::new_unchecked(ptr as *mut ())
raw_proc: NonNull::new_unchecked(ptr as *mut ()),
});
}

Expand Down Expand Up @@ -514,7 +514,7 @@ where
where
F: Future<Output = R> + Send + 'static,
R: Send + 'static,
S: Fn(LightProc) + Send + Sync + 'static
S: Fn(LightProc) + Send + Sync + 'static,
{
fn drop(&mut self) {
let raw = self.0;
Expand Down

0 comments on commit 929b1e9

Please sign in to comment.