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

Quelle  ref_count.rs

  Sprache: Rust
 

use core::sync::atomic::{fence, AtomicI32, Ordering};

#[repr(transparent)]
#[derive(Default)]
pub struct RefCount(pub(crate) AtomicI32);

impl RefCount {
    /// Creates a new `RefCount` with an initial value of `1`.
    pub fn new(count: u32) -> Self {
        Self(AtomicI32::new(count as i32))
    }

    /// Increments the reference count, returning the new value.
    pub fn add_ref(&self) -> u32 {
        (self.0.fetch_add(1, Ordering::Relaxed) + 1as u32
    }

    /// Decrements the reference count, returning the new value.
    ///
    /// This operation inserts an `Acquire` fence when the reference count reaches zero.
    /// This prevents reordering before the object is destroyed.
    pub fn release(&self) -> u32 {
        let remaining = self.0.fetch_sub(1, Ordering::Release) - 1;

        match remaining.cmp(&0) {
            core::cmp::Ordering::Equal => fence(Ordering::Acquire),
            core::cmp::Ordering::Less => panic!("Object has been over-released."),
            core::cmp::Ordering::Greater => {}
        }

        remaining as u32
    }
}

Messung V0.5 in Prozent
C=82 H=100 G=91

¤ Dauer der Verarbeitung: 0.18 Sekunden  (vorverarbeitet am  2026-06-22) ¤

*© 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.