mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #26220 - servo:layout-2020-rule-tree-new-on-write, r=emilio
Always upgrade existing weak child references in the rule tree Just because we didn't find a child when read-locking a node children list doesn't mean it still won't exist while we wait to upgrade the read lock into a write lock to create the child.
This commit is contained in:
commit
00ac447966
1 changed files with 25 additions and 12 deletions
|
@ -402,18 +402,31 @@ impl StrongRuleNode {
|
||||||
return child.upgrade();
|
return child.upgrade();
|
||||||
}
|
}
|
||||||
let mut children = RwLockUpgradableReadGuard::upgrade(children);
|
let mut children = RwLockUpgradableReadGuard::upgrade(children);
|
||||||
let weak = children.get_or_insert_with(
|
let mut is_new = false;
|
||||||
|
let weak = {
|
||||||
|
let is_new = &mut is_new;
|
||||||
|
children.get_or_insert_with(
|
||||||
key,
|
key,
|
||||||
|node| node.p.key(),
|
|node| node.p.key(),
|
||||||
move || {
|
move || {
|
||||||
|
*is_new = true;
|
||||||
let root = unsafe { root.downgrade() };
|
let root = unsafe { root.downgrade() };
|
||||||
let strong =
|
let strong = StrongRuleNode::new(Box::new(RuleNode::new(
|
||||||
StrongRuleNode::new(Box::new(RuleNode::new(root, self.clone(), source, level)));
|
root,
|
||||||
|
self.clone(),
|
||||||
|
source,
|
||||||
|
level,
|
||||||
|
)));
|
||||||
let weak = unsafe { strong.downgrade() };
|
let weak = unsafe { strong.downgrade() };
|
||||||
mem::forget(strong);
|
mem::forget(strong);
|
||||||
weak
|
weak
|
||||||
},
|
},
|
||||||
);
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
if !is_new {
|
||||||
|
return weak.upgrade();
|
||||||
|
}
|
||||||
|
|
||||||
unsafe { StrongRuleNode::from_unsafe_box(UnsafeBox::clone(&weak.p)) }
|
unsafe { StrongRuleNode::from_unsafe_box(UnsafeBox::clone(&weak.p)) }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue