diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-10-21 09:07:30 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-10-21 09:07:30 -0600 |
commit | 2de5407cdabef67ed03b2ad4edf4a22541d77875 (patch) | |
tree | 11eb382a303f1175ae0f2df6a6169ca412201466 /components/script_traits | |
parent | 252e73ff9b43abdeee4eac37702ef2e3adef0062 (diff) | |
parent | 553a0dbefd8a8724f7c894b1c25e6c15c35d6d04 (diff) | |
download | servo-2de5407cdabef67ed03b2ad4edf4a22541d77875.tar.gz servo-2de5407cdabef67ed03b2ad4edf4a22541d77875.zip |
Auto merge of #7450 - benschulz:constellation-timer, r=jdm
Ordering guarantees for timers
This is an rough solution to the issue described in #3396. XHRs still do their own thing and an overall clean up is in order. Before I do that, though, I'd really like someone to sign off on the overall idea.
There's one major difference to what jdm layed out #3396: The timers remain with the window/worker and only the earliest expiring one is coordinated with the dedicated timer thread.
That means both the timer thread and the window/worker have to keep track of which timer expires next, which feels a bit wonky. However, the upshot is that there's no need for communication with the timer thread when a pipeline is frozen, thawed or dropped.
Most relvant parts are
- the [`TimerScheduler`](https://github.com/servo/servo/commit/6f5f6619586379982321b5de7583d387df184504#diff-74137a6f50ab38e7a1e4d16920a66ce7R73), which is the new per-constellation timer task and
- the [`ActiveTimers`](https://github.com/servo/servo/commit/6f5f6619586379982321b5de7583d387df184504#diff-86707d952414a2860b78bcf6c1db8e2eR34) which is what's left on the window/worker side.
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7450)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script_traits')
-rw-r--r-- | components/script_traits/Cargo.toml | 1 | ||||
-rw-r--r-- | components/script_traits/lib.rs | 59 |
2 files changed, 58 insertions, 2 deletions
diff --git a/components/script_traits/Cargo.toml b/components/script_traits/Cargo.toml index d038ce36f39..11e3b077096 100644 --- a/components/script_traits/Cargo.toml +++ b/components/script_traits/Cargo.toml @@ -38,3 +38,4 @@ libc = "0.1" euclid = "0.2" serde = "0.6" serde_macros = "0.5" +time = "0.1.12" diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs index 7693529d4b1..3c04fa36dda 100644 --- a/components/script_traits/lib.rs +++ b/components/script_traits/lib.rs @@ -19,11 +19,13 @@ extern crate msg; extern crate net_traits; extern crate profile_traits; extern crate serde; +extern crate time; extern crate url; extern crate util; use app_units::Au; use devtools_traits::ScriptToDevtoolsControlMsg; +use euclid::length::Length; use euclid::point::Point2D; use euclid::rect::Rect; use ipc_channel::ipc::{IpcReceiver, IpcSender}; @@ -36,10 +38,11 @@ use msg::webdriver_msg::WebDriverScriptCommand; use net_traits::ResourceTask; use net_traits::image_cache_task::ImageCacheTask; use net_traits::storage_task::StorageTask; -use profile_traits::{mem, time}; +use profile_traits::mem; use std::any::Any; use std::sync::mpsc::{Receiver, Sender}; use url::Url; +use util::mem::HeapSizeOf; /// The address of a node. Layout sends these back. They must be validated via /// `from_untrusted_node_address` before they can be used, because we do not trust layout. @@ -177,6 +180,56 @@ pub enum CompositorEvent { /// crates that don't need to know about them. pub struct OpaqueScriptLayoutChannel(pub (Box<Any + Send>, Box<Any + Send>)); +/// Requests a TimerEvent-Message be sent after the given duration. +pub struct TimerEventRequest(pub Box<TimerEventChan + Send>, pub TimerSource, pub TimerEventId, pub MsDuration); + +/// Notifies the script task to fire due timers. +/// TimerSource must be FromWindow when dispatched to ScriptTask and +/// must be FromWorker when dispatched to a DedicatedGlobalWorkerScope +pub struct TimerEvent(pub TimerSource, pub TimerEventId); + +/// A cloneable interface for sending timer events. +pub trait TimerEventChan { + /// Send a timer event to the associated event loop. + fn send(&self, msg: TimerEvent) -> Result<(), ()>; + /// Clone this handle. + fn clone(&self) -> Box<TimerEventChan + Send>; +} + +/// Describes the task that requested the TimerEvent. +#[derive(Copy, Clone, HeapSizeOf)] +pub enum TimerSource { + /// The event was requested from a window (ScriptTask). + FromWindow(PipelineId), + /// The event was requested from a worker (DedicatedGlobalWorkerScope). + FromWorker +} + +/// The id to be used for a TimerEvent is defined by the corresponding TimerEventRequest. +#[derive(PartialEq, Eq, Copy, Clone, Debug, HeapSizeOf)] +pub struct TimerEventId(pub u32); + +/// Unit of measurement. +#[derive(Clone, Copy, HeapSizeOf)] +pub enum Milliseconds {} +/// Unit of measurement. +#[derive(Clone, Copy, HeapSizeOf)] +pub enum Nanoseconds {} + +/// Amount of milliseconds. +pub type MsDuration = Length<Milliseconds, u64>; +/// Amount of nanoseconds. +pub type NsDuration = Length<Nanoseconds, u64>; + +/// Returns the duration since an unspecified epoch measured in ms. +pub fn precise_time_ms() -> MsDuration { + Length::new(time::precise_time_ns() / (1000 * 1000)) +} +/// Returns the duration since an unspecified epoch measured in ns. +pub fn precise_time_ns() -> NsDuration { + Length::new(time::precise_time_ns()) +} + /// Data needed to construct a script thread. pub struct InitialScriptState { /// The ID of the pipeline with which this script thread is associated. @@ -192,6 +245,8 @@ pub struct InitialScriptState { pub control_port: Receiver<ConstellationControlMsg>, /// A channel on which messages can be sent to the constellation from script. pub constellation_chan: ConstellationChan, + /// A channel to schedule timer events. + pub scheduler_chan: Sender<TimerEventRequest>, /// Information that script sends out when it panics. pub failure_info: Failure, /// A channel to the resource manager task. @@ -201,7 +256,7 @@ pub struct InitialScriptState { /// A channel to the image cache task. pub image_cache_task: ImageCacheTask, /// A channel to the time profiler thread. - pub time_profiler_chan: time::ProfilerChan, + pub time_profiler_chan: profile_traits::time::ProfilerChan, /// A channel to the memory profiler thread. pub mem_profiler_chan: mem::ProfilerChan, /// A channel to the developer tools, if applicable. |