Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  mod.rs

  Sprache: Rust
 

// Copyright (c) the JPEG XL Project Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#![allow(unsafe_code)]

use std::cell::UnsafeCell;
use std::sync::atomic::AtomicUsize;

mod internal;

pub use internal::{AtomicRef, AtomicRefMut};

pub struct AtomicRefCell<T: ?Sized> {
    counter: AtomicUsize,
    data: UnsafeCell<T>,
}

impl<T> AtomicRefCell<T> {
    #[inline]
    pub const fn new(value: T) -> Self {
        Self {
            counter: AtomicUsize::new(0),
            data: UnsafeCell::new(value),
        }
    }
}

impl<T: ?Sized> AtomicRefCell<T> {
    #[inline]
    pub fn borrow(&self) -> AtomicRef<'_, T> {
        AtomicRef::new(self).unwrap()
    }

    #[inline]
    pub fn try_borrow(&self) -> Option<AtomicRef<'_, T>> {
        AtomicRef::new(self)
    }

    #[inline]
    pub fn borrow_mut(&self) -> AtomicRefMut<'_, T> {
        AtomicRefMut::new(self).unwrap()
    }

    #[inline]
    pub fn try_borrow_mut(&self) -> Option<AtomicRefMut<'_, T>> {
        AtomicRefMut::new(self)
    }
}

// SAFETY: Accesses to the inner data are synchronized by the atomic reference counter.
unsafe impl<T: ?Sized + Send> Send for AtomicRefCell<T> {}

// SAFETY: Accesses to the inner data are synchronized by the atomic reference counter. Additional
// `Send` bound is needed because `AtomicRefCell` provides mutable access behind a shared reference.
unsafe impl<T: ?Sized + Send + Sync> Sync for AtomicRefCell<T> {}

impl<T: std::fmt::Debug> std::fmt::Debug for AtomicRefCell<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let val = self.try_borrow();
        if let Some(val) = val {
            f.debug_tuple("AtomicRefCell").field(&*val).finish()
        } else {
            f.debug_tuple("AtomicRefCell")
                .field(&format_args!("[borrowed]"))
                .finish()
        }
    }
}

Messung V0.5 in Prozent
C=87 H=94 G=90

¤ Dauer der Verarbeitung: 0.4 Sekunden  ¤

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






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002