aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/task.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2017-09-17 17:30:21 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2017-09-18 02:47:06 +0200
commit5412767f466861a9b0ad08b3a65744c3f3b17e09 (patch)
treebba585ebbb17c491120f39657ed359c0af9b3110 /components/script/task.rs
parent46628fba05a548c1c2141d7c709b6e5d812f3114 (diff)
downloadservo-5412767f466861a9b0ad08b3a65744c3f3b17e09.tar.gz
servo-5412767f466861a9b0ad08b3a65744c3f3b17e09.zip
Introduce a task! macro and use it for internal pause steps
Diffstat (limited to 'components/script/task.rs')
-rw-r--r--components/script/task.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/components/script/task.rs b/components/script/task.rs
index 55c8f37aca4..35f202480ca 100644
--- a/components/script/task.rs
+++ b/components/script/task.rs
@@ -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)]