style: Make WorkQueue creation fallible.

Fixes bug 1290205 in bugzilla.
This commit is contained in:
Emilio Cobos Álvarez 2016-08-25 11:37:55 -07:00
parent 8a5e1b70b7
commit 4194ba063a
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
4 changed files with 43 additions and 15 deletions

View file

@ -38,7 +38,7 @@ pub struct PerDocumentStyleData {
pub expired_animations: Arc<RwLock<HashMap<OpaqueNode, Vec<Animation>>>>,
// FIXME(bholley): This shouldn't be per-document.
pub work_queue: WorkQueue<SharedStyleContext, WorkQueueData>,
pub work_queue: Option<WorkQueue<SharedStyleContext, WorkQueueData>>,
pub num_threads: usize,
}
@ -68,7 +68,11 @@ impl PerDocumentStyleData {
new_animations_receiver: new_anims_receiver,
running_animations: Arc::new(RwLock::new(HashMap::new())),
expired_animations: Arc::new(RwLock::new(HashMap::new())),
work_queue: WorkQueue::new("StyleWorker", thread_state::LAYOUT, *NUM_THREADS),
work_queue: if *NUM_THREADS <= 1 {
None
} else {
WorkQueue::new("StyleWorker", thread_state::LAYOUT, *NUM_THREADS).ok()
},
num_threads: *NUM_THREADS,
}
}
@ -91,6 +95,8 @@ impl PerDocumentStyleData {
impl Drop for PerDocumentStyleData {
fn drop(&mut self) {
self.work_queue.shutdown();
if let Some(ref mut queue) = self.work_queue {
queue.shutdown();
}
}
}

View file

@ -103,11 +103,11 @@ fn restyle_subtree(node: GeckoNode, raw_data: *mut RawServoStyleSet) {
// We ensure this is true before calling Servo_RestyleSubtree()
debug_assert!(node.is_dirty() || node.has_dirty_descendants());
if per_doc_data.num_threads == 1 {
if per_doc_data.num_threads == 1 || per_doc_data.work_queue.is_none() {
sequential::traverse_dom::<GeckoNode, RecalcStyleOnly>(node, &shared_style_context);
} else {
parallel::traverse_dom::<GeckoNode, RecalcStyleOnly>(node, &shared_style_context,
&mut per_doc_data.work_queue);
per_doc_data.work_queue.as_mut().unwrap());
}
}