use std::future::Future; use std::pin::Pin; use std::sync::atomic::{AtomicUsize, Ordering}; use std::task::{Context, Poll}; use std::thread; use std::time::Duration;
use async_task::Runnable; use easy_parallel::Parallel; use smol::future;
// Creates a future with event counters. // // Usage: `future!(f, POLL, DROP_F, DROP_T)` // // The future `f` outputs `Poll::Ready`. // When it gets polled, `POLL` is incremented. // When it gets dropped, `DROP_F` is incremented. // When the output gets dropped, `DROP_T` is incremented.
macro_rules! future {
($name:pat, $poll:ident, $drop_f:ident, $drop_t:ident) => { static $poll: AtomicUsize = AtomicUsize::new(0); static $drop_f: AtomicUsize = AtomicUsize::new(0); static $drop_t: AtomicUsize = AtomicUsize::new(0);
impl Drop for Fut { fn drop(&mutself) {
$drop_f.fetch_add(1, Ordering::SeqCst);
}
}
#[derive(Default)] struct Out(Box<i32>, bool);
impl Drop for Out { fn drop(&mutself) { ifself.1 {
$drop_t.fetch_add(1, Ordering::SeqCst);
}
}
}
Fut(Box::new(0))
};
};
}
// Creates a schedule function with event counters. // // Usage: `schedule!(s, SCHED, DROP)` // // The schedule function `s` does nothing. // When it gets invoked, `SCHED` is incremented. // When it gets dropped, `DROP` is incremented.
macro_rules! schedule {
($name:pat, $sched:ident, $drop:ident) => { static $drop: AtomicUsize = AtomicUsize::new(0); static $sched: AtomicUsize = AtomicUsize::new(0);
let $name = { struct Guard(Box<i32>);
impl Drop for Guard { fn drop(&mutself) {
$drop.fetch_add(1, Ordering::SeqCst);
}
}
let guard = Guard(Box::new(0)); move |runnable: Runnable| { let _ = &guard;
runnable.schedule();
$sched.fetch_add(1, Ordering::SeqCst);
}
};
};
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.