euv-core 0.52.1

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Updates an atomic peak high-water mark using a lock-free compare-exchange loop.
///
/// # Arguments
///
/// - `&AtomicUsize` - Peak depth atomic counter.
/// - `usize` - Newly observed queue depth.
pub(crate) fn update_atomic_peak(peak: &AtomicUsize, observed: usize) {
    let mut current: usize = peak.load(Ordering::Relaxed);
    while observed > current {
        match peak.compare_exchange_weak(current, observed, Ordering::AcqRel, Ordering::Relaxed) {
            Ok(_) => break,
            Err(actual) => current = actual,
        }
    }
}

/// Returns the combined number of buffered tasks across all three priority lanes.
///
/// # Arguments
///
/// - `&UiDispatcherQueues` - Synchronized priority queue container.
///
/// # Returns
///
/// - `usize` - Total queued task count.
#[must_use]
pub(crate) fn total_queued_tasks(queues: &UiDispatcherQueues) -> usize {
    queues
        .get_critical()
        .len()
        .saturating_add(queues.get_normal().len())
        .saturating_add(queues.get_background().len())
}

/// Pops the next task in strict priority (`Critical` -> `Normal` -> `Background`) and FIFO order.
///
/// # Arguments
///
/// - `&mut UiDispatcherQueues` - Mutable synchronized priority queue container.
///
/// # Returns
///
/// - `Option<UiDispatchTask>` - Highest-priority oldest task, or `None` when empty.
pub(crate) fn pop_next_prioritized_task(queues: &mut UiDispatcherQueues) -> Option<UiDispatchTask> {
    if let Some(task) = queues.get_mut_critical().pop_front() {
        return Some(task);
    }
    if let Some(task) = queues.get_mut_normal().pop_front() {
        return Some(task);
    }
    queues.get_mut_background().pop_front()
}

/// Evicts the oldest task from the lowest-priority non-empty lane under `DropOldest` backpressure.
///
/// # Arguments
///
/// - `&mut UiDispatcherQueues` - Mutable synchronized priority queue container.
///
/// # Returns
///
/// - `bool` - `true` when an older task was evicted to make room.
pub(crate) fn drop_oldest_lowest_priority_task(queues: &mut UiDispatcherQueues) -> bool {
    if queues.get_mut_background().pop_front().is_some() {
        return true;
    }
    if queues.get_mut_normal().pop_front().is_some() {
        return true;
    }
    queues.get_mut_critical().pop_front().is_some()
}