aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout/context.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-11-03 21:37:17 -0500
committerGitHub <noreply@github.com>2016-11-03 21:37:17 -0500
commit7b803860470029a6deadb4d50fc401ddce968f6c (patch)
treebbd40f4f5039942bb57965ef6172c17f680441a0 /components/layout/context.rs
parent97e205c8ef01545ad8abcf7ac2efa9e53b846847 (diff)
parent4d14f1eb67798ec13e7a8f45c5c59a3cc8433423 (diff)
downloadservo-7b803860470029a6deadb4d50fc401ddce968f6c.tar.gz
servo-7b803860470029a6deadb4d50fc401ddce968f6c.zip
Auto merge of #14048 - antrik:nosync-ipc_sender, r=mbrubeck
layout/context: Wrap `image_cache_thread` in a `Mutex<>` as well `SharedLayoutContext.image_cache_thread` didn't get the `Mutex<>` treatment along with all the other channels in there, because `ipc-channel::Sender` is presently inherently `Sync`. I believe this to be an implementation accident though, that should be rectified in the future -- not something users should actually rely on... Note that sharing senders (be it `mpsc` or `ipc-channel`) in is probably not a good idea anyway: just cloning them -- and letting them handle the sharing internally -- should be both simpler and cheaper. But right now that's how things are handled here; so let's go with the flow... <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14048) <!-- Reviewable:end -->
Diffstat (limited to 'components/layout/context.rs')
-rw-r--r--components/layout/context.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/components/layout/context.rs b/components/layout/context.rs
index 0b3973eac05..308295f4196 100644
--- a/components/layout/context.rs
+++ b/components/layout/context.rs
@@ -77,7 +77,7 @@ pub struct SharedLayoutContext {
pub style_context: SharedStyleContext,
/// The shared image cache thread.
- pub image_cache_thread: ImageCacheThread,
+ pub image_cache_thread: Mutex<ImageCacheThread>,
/// A channel for the image cache to send responses to.
pub image_cache_sender: Mutex<ImageCacheChan>,
@@ -133,7 +133,8 @@ impl SharedLayoutContext {
debug_assert!(opts::get().output_file.is_some() || opts::get().exit_after_load);
// See if the image is already available
- let result = self.image_cache_thread.find_image(url.clone(), use_placeholder);
+ let result = self.image_cache_thread.lock().unwrap()
+ .find_image(url.clone(), use_placeholder);
match result {
Ok(image) => return Some(image),
@@ -147,7 +148,7 @@ impl SharedLayoutContext {
// If we are emitting an output file, then we need to block on
// image load or we risk emitting an output file missing the image.
let (sync_tx, sync_rx) = ipc::channel().unwrap();
- self.image_cache_thread.request_image(url, ImageCacheChan(sync_tx), None);
+ self.image_cache_thread.lock().unwrap().request_image(url, ImageCacheChan(sync_tx), None);
loop {
match sync_rx.recv() {
Err(_) => return None,
@@ -171,7 +172,8 @@ impl SharedLayoutContext {
.map(|img| ImageOrMetadataAvailable::ImageAvailable(img));
}
// See if the image is already available
- let result = self.image_cache_thread.find_image_or_metadata(url.clone(),
+ let result = self.image_cache_thread.lock().unwrap()
+ .find_image_or_metadata(url.clone(),
use_placeholder);
match result {
Ok(image_or_metadata) => Some(image_or_metadata),
@@ -180,7 +182,8 @@ impl SharedLayoutContext {
// Not yet requested, async mode - request image or metadata from the cache
Err(ImageState::NotRequested) => {
let sender = self.image_cache_sender.lock().unwrap().clone();
- self.image_cache_thread.request_image_and_metadata(url, sender, None);
+ self.image_cache_thread.lock().unwrap()
+ .request_image_and_metadata(url, sender, None);
None
}
// Image has been requested, is still pending. Return no image for this paint loop.