Struct style::rule_tree::core::RuleNode

source ·
struct RuleNode {
    root: Option<WeakRuleNode>,
    parent: Option<StrongRuleNode>,
    source: Option<StyleSource>,
    cascade_priority: CascadePriority,
    refcount: AtomicUsize,
    approximate_free_count: AtomicUsize,
    children: RwLock<Map<ChildKey, WeakRuleNode>>,
    next_free: AtomicPtr<RuleNode>,
}
Expand description

A node in the rule tree.

Fields§

§root: Option<WeakRuleNode>

The root node. Only the root has no root pointer, for obvious reasons.

§parent: Option<StrongRuleNode>

The parent rule node. Only the root has no parent.

§source: Option<StyleSource>

The actual style source, either coming from a selector in a StyleRule, or a raw property declaration block (like the style attribute).

None for the root node.

§cascade_priority: CascadePriority

The cascade level + layer order this rule is positioned at.

§refcount: AtomicUsize

The refcount of this node.

Starts at one. Incremented in StrongRuleNode::clone and WeakRuleNode::upgrade. Decremented in StrongRuleNode::drop and RuleTree::swap_free_list_and_gc.

If a non-root node’s refcount reaches zero, it is incremented back to at least one in RuleNode::pretend_to_be_on_free_list until the caller who observed it dropping to zero had a chance to try to remove it from its parent’s children list.

The refcount should never be decremented to zero if the value in next_free is not null.

§approximate_free_count: AtomicUsize

Only used for the root, stores the number of free rule nodes that are around.

§children: RwLock<Map<ChildKey, WeakRuleNode>>

The children of a given rule node. Children remove themselves from here when they go away.

§next_free: AtomicPtr<RuleNode>

This field has two different meanings depending on whether this is the root node or not.

If it is the root, it represents the head of the free list. It may be null, which means the free list is gone because the tree was dropped, and it may be RuleNode::DANGLING_PTR, which means the free list is empty.

If it is not the root node, this field is either null if the node is not on the free list, RuleNode::DANGLING_PTR if it is the last item on the free list or the node is pretending to be on the free list, or any valid non-null pointer representing the next item on the free list after this one.

See RuleNode::push_on_free_list, swap_free_list_and_gc, and WeakRuleNode::upgrade.

Two threads should never attempt to put the same node on the free list both at the same time.

Implementations§

source§

impl RuleNode

source

const DANGLING_PTR: *mut Self = {0x8 as *mut rule_tree::core::RuleNode}

source

unsafe fn new( root: WeakRuleNode, parent: StrongRuleNode, source: StyleSource, cascade_priority: CascadePriority, ) -> Self

source

fn root() -> Self

source

fn key(&self) -> ChildKey

source

unsafe fn drop_without_free_list(this: &mut UnsafeBox<Self>)

Drops a node without ever putting it on the free list.

Note that the node may not be dropped if we observe that its refcount isn’t zero anymore when we write-lock its parent’s children map to remove it.

This loops over parents of dropped nodes if their own refcount reaches zero to avoid recursion when dropping deep hierarchies of nodes.

For non-root nodes, this should always be preceded by a call of RuleNode::pretend_to_be_on_free_list.

source

unsafe fn push_on_free_list(this: &UnsafeBox<Self>) -> bool

Pushes this node on the tree’s free list. Returns false if the free list is gone. Should only be called after we decremented a node’s refcount to zero and pretended to be on the free list.

source

unsafe fn pretend_to_be_on_free_list(this: &UnsafeBox<Self>)

Makes the node pretend to be on the free list. This will increment the refcount by 1 and store Self::DANGLING_PTR in next_free. This method should only be called after caller decremented the refcount to zero, with the null pointer stored in next_free.

source

fn as_mut_ptr(&self) -> *mut RuleNode

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> MaybeBoxed<Box<T>> for T

source§

fn maybe_boxed(self) -> Box<T>

Convert
source§

impl<T> MaybeBoxed<T> for T

source§

fn maybe_boxed(self) -> T

Convert
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T