Make style context use parking_lot::RwLock

This commit is contained in:
Xidorn Quan 2016-11-01 11:43:16 +11:00
parent 070dee3542
commit 09cbe3bce0
11 changed files with 23 additions and 15 deletions

View file

@ -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"}

View file

@ -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<WebRenderImageInfo> {
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)

View file

@ -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;

View file

@ -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"}

View file

@ -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);

View file

@ -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",

View file

@ -672,7 +672,7 @@ pub fn complete_expired_transitions(node: OpaqueNode, style: &mut Arc<ComputedVa
context: &SharedStyleContext) -> 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<ComputedVa
}
if had_animations_to_expire {
context.expired_animations.write().unwrap().remove(&node);
context.expired_animations.write().remove(&node);
}
had_animations_to_expire

View file

@ -10,10 +10,11 @@ use dom::OpaqueNode;
use error_reporting::ParseErrorReporter;
use euclid::Size2D;
use matching::{ApplicableDeclarationsCache, StyleSharingCandidateCache};
use parking_lot::RwLock;
use selector_matching::Stylist;
use std::cell::RefCell;
use std::collections::HashMap;
use std::sync::{Arc, Mutex, RwLock};
use std::sync::{Arc, Mutex};
use std::sync::mpsc::Sender;
use timer::Timer;

View file

@ -12,11 +12,12 @@ use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
use media_queries::{Device, MediaType};
use num_cpus;
use parallel::WorkQueueData;
use parking_lot::RwLock;
use selector_matching::Stylist;
use std::cmp;
use std::collections::HashMap;
use std::env;
use std::sync::{Arc, RwLock};
use std::sync::Arc;
use std::sync::mpsc::{Receiver, Sender, channel};
use style_traits::ViewportPx;
use stylesheets::Stylesheet;

View file

@ -605,11 +605,10 @@ trait PrivateMatchMethods: TElement {
// Merge any running transitions into the current style, and cancel them.
let had_running_animations = context.running_animations
.read()
.unwrap()
.get(&this_opaque)
.is_some();
if had_running_animations {
let mut all_running_animations = context.running_animations.write().unwrap();
let mut all_running_animations = context.running_animations.write();
for mut running_animation in all_running_animations.get_mut(&this_opaque).unwrap() {
// This shouldn't happen frequently, but under some
// circumstances mainly huge load or debug builds, the

2
ports/cef/Cargo.lock generated
View file

@ -1056,6 +1056,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",
@ -1094,6 +1095,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",