Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/gpu-alloc/src/   (Firefox Browser Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 1 kB image not shown  

Quelle  util.rs

  Sprache: Rust
 

use alloc::sync::Arc;

/// Guarantees uniqueness only if `Weak` pointers are never created
/// from this `Arc` or clones.
pub(cratefn is_arc_unique<M>(arc: &mut Arc<M>) -> bool {
    let strong_count = Arc::strong_count(&*arc);
    debug_assert_ne!(strong_count, 0"This Arc should exist");

    debug_assert!(
        strong_count > 1 || Arc::get_mut(arc).is_some(),
        "`Weak` pointer exists"
    );

    strong_count == 1
}

/// Can be used instead of `Arc::try_unwrap(arc).unwrap()`
/// when it is guaranteed to succeed.
pub(crateunsafe fn arc_unwrap<M>(mut arc: Arc<M>) -> M {
    use core::{mem::ManuallyDrop, ptr::read};
    debug_assert!(is_arc_unique(&mut arc));

    // Get raw pointer to inner value.
    let raw = Arc::into_raw(arc);

    // As `Arc` is unique and no Weak pointers exist
    // it won't be dereferenced elsewhere.
    let inner = read(raw);

    // Cast to `ManuallyDrop` which guarantees to have same layout
    // and will skip dropping.
    drop(Arc::from_raw(raw as *const ManuallyDrop<M>));
    inner
}

/// Can be used instead of `Arc::try_unwrap`
/// only if `Weak` pointers are never created from this `Arc` or clones.
pub(crateunsafe fn try_arc_unwrap<M>(mut arc: Arc<M>) -> Option<M> {
    if is_arc_unique(&mut arc) {
        Some(arc_unwrap(arc))
    } else {
        None
    }
}

Messung V0.5 in Prozent
C=61 H=92 G=77

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet am  2026-06-18) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.