From 09cbe3bce032a965d613a4ae579a02d86a7c9e51 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Tue, 1 Nov 2016 11:43:16 +1100 Subject: [PATCH] Make style context use parking_lot::RwLock --- components/layout/Cargo.toml | 1 + components/layout/context.rs | 8 +++----- components/layout/lib.rs | 1 + components/layout_thread/Cargo.toml | 1 + components/layout_thread/lib.rs | 10 ++++++---- components/servo/Cargo.lock | 2 ++ components/style/animation.rs | 4 ++-- components/style/context.rs | 3 ++- components/style/gecko/data.rs | 3 ++- components/style/matching.rs | 3 +-- ports/cef/Cargo.lock | 2 ++ 11 files changed, 23 insertions(+), 15 deletions(-) diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml index 6b7dabd9f15..917b6b82e73 100644 --- a/components/layout/Cargo.toml +++ b/components/layout/Cargo.toml @@ -27,6 +27,7 @@ log = "0.3.5" msg = {path = "../msg"} net_traits = {path = "../net_traits"} ordered-float = "0.2.2" +parking_lot = {version = "0.3.3", features = ["nightly"]} plugins = {path = "../plugins"} profile_traits = {path = "../profile_traits"} range = {path = "../range"} diff --git a/components/layout/context.rs b/components/layout/context.rs index 17a484e2930..0b3973eac05 100644 --- a/components/layout/context.rs +++ b/components/layout/context.rs @@ -16,11 +16,12 @@ use ipc_channel::ipc; use net_traits::image::base::Image; use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheThread, ImageResponse, ImageState}; use net_traits::image_cache_thread::{ImageOrMetadataAvailable, UsePlaceholder}; +use parking_lot::RwLock; use std::cell::{RefCell, RefMut}; use std::collections::HashMap; use std::hash::BuildHasherDefault; use std::rc::Rc; -use std::sync::{Arc, Mutex, RwLock}; +use std::sync::{Arc, Mutex}; use style::context::{LocalStyleContext, StyleContext, SharedStyleContext}; use url::Url; use util::opts; @@ -194,7 +195,6 @@ impl SharedLayoutContext { -> Option { if let Some(existing_webrender_image) = self.webrender_image_cache .read() - .unwrap() .get(&((*url).clone(), use_placeholder)) { return Some((*existing_webrender_image).clone()) } @@ -205,9 +205,7 @@ impl SharedLayoutContext { if image_info.key.is_none() { Some(image_info) } else { - let mut webrender_image_cache = self.webrender_image_cache - .write() - .unwrap(); + let mut webrender_image_cache = self.webrender_image_cache.write(); webrender_image_cache.insert(((*url).clone(), use_placeholder), image_info); Some(image_info) diff --git a/components/layout/lib.rs b/components/layout/lib.rs index bff6eeca1ac..935a7631e23 100644 --- a/components/layout/lib.rs +++ b/components/layout/lib.rs @@ -36,6 +36,7 @@ extern crate log; extern crate msg; extern crate net_traits; extern crate ordered_float; +extern crate parking_lot; #[macro_use] #[no_link] extern crate plugins as servo_plugins; diff --git a/components/layout_thread/Cargo.toml b/components/layout_thread/Cargo.toml index 37998d1b48b..368c6142980 100644 --- a/components/layout_thread/Cargo.toml +++ b/components/layout_thread/Cargo.toml @@ -25,6 +25,7 @@ lazy_static = "0.2" log = "0.3.5" msg = {path = "../msg"} net_traits = {path = "../net_traits"} +parking_lot = {version = "0.3.3", features = ["nightly"]} plugins = {path = "../plugins"} profile_traits = {path = "../profile_traits"} script = {path = "../script"} diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 8016bb68b44..32231f1808b 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -32,6 +32,7 @@ extern crate lazy_static; extern crate log; extern crate msg; extern crate net_traits; +extern crate parking_lot; #[macro_use] extern crate profile_traits; extern crate script; @@ -83,6 +84,7 @@ use layout_traits::LayoutThreadFactory; use msg::constellation_msg::PipelineId; use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheResult, ImageCacheThread}; use net_traits::image_cache_thread::UsePlaceholder; +use parking_lot::RwLock; use profile_traits::mem::{self, Report, ReportKind, ReportsChan}; use profile_traits::time::{self, TimerMetadata, profile}; use profile_traits::time::{TimerMetadataFrameType, TimerMetadataReflowType}; @@ -101,7 +103,7 @@ use std::collections::HashMap; use std::hash::BuildHasherDefault; use std::ops::{Deref, DerefMut}; use std::process; -use std::sync::{Arc, Mutex, MutexGuard, RwLock}; +use std::sync::{Arc, Mutex, MutexGuard}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::mpsc::{Receiver, Sender, channel}; use style::animation::Animation; @@ -1316,7 +1318,7 @@ impl LayoutThread { if let Some(mut root_flow) = self.root_flow.clone() { // Perform an abbreviated style recalc that operates without access to the DOM. - let animations = self.running_animations.read().unwrap(); + let animations = self.running_animations.read(); profile(time::ProfilerCategory::LayoutStyleRecalc, self.profiler_metadata(), self.time_profiler_chan.clone(), @@ -1368,8 +1370,8 @@ impl LayoutThread { // Kick off animations if any were triggered, expire completed ones. animation::update_animation_state(&self.constellation_chan, &self.script_chan, - &mut *self.running_animations.write().unwrap(), - &mut *self.expired_animations.write().unwrap(), + &mut *self.running_animations.write(), + &mut *self.expired_animations.write(), &self.new_animations_receiver, self.id, &self.timer); diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 0936aa8f0fc..7cdf39b2fc8 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -1149,6 +1149,7 @@ dependencies = [ "msg 0.0.1", "net_traits 0.0.1", "ordered-float 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "profile_traits 0.0.1", "range 0.0.1", @@ -1194,6 +1195,7 @@ dependencies = [ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", "net_traits 0.0.1", + "parking_lot 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "profile_traits 0.0.1", "script 0.0.1", diff --git a/components/style/animation.rs b/components/style/animation.rs index 3cdc057d532..898dd8ee449 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -672,7 +672,7 @@ pub fn complete_expired_transitions(node: OpaqueNode, style: &mut Arc bool { let had_animations_to_expire; { - let all_expired_animations = context.expired_animations.read().unwrap(); + let all_expired_animations = context.expired_animations.read(); let animations_to_expire = all_expired_animations.get(&node); had_animations_to_expire = animations_to_expire.is_some(); if let Some(ref animations) = animations_to_expire { @@ -686,7 +686,7 @@ pub fn complete_expired_transitions(node: OpaqueNode, style: &mut Arc