Introduce a task! macro and use it for internal pause steps

This commit is contained in:
Anthony Ramine 2017-09-17 17:30:21 +02:00
parent 46628fba05
commit 5412767f46
3 changed files with 29 additions and 10 deletions

View file

@ -9,6 +9,26 @@ use std::intrinsics;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
macro_rules! task {
($name:ident: move || $body:tt) => {{
#[allow(non_camel_case_types)]
struct $name<F>(F);
impl<F> ::task::Task for $name<F>
where
F: ::std::ops::FnOnce(),
{
fn name(&self) -> &'static str {
stringify!($name)
}
fn run(self: Box<Self>) {
(self.0)();
}
}
$name(move || $body)
}};
}
/// A task that can be run. The name method is for profiling purposes.
pub trait Task {
#[allow(unsafe_code)]