mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Introduce a task! macro and use it for internal pause steps
This commit is contained in:
parent
46628fba05
commit
5412767f46
3 changed files with 29 additions and 10 deletions
|
@ -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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue