Sha256: 882c455951c81acccc523e0a0127808df1dc2ec710ea303f592edfde2f8c11bb

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

use std::sync::{self, MutexGuard, TryLockError};

/// Adapter for `std::Mutex` that removes the poisoning aspects
/// from its api.
#[derive(Debug)]
pub(crate) struct Mutex<T: ?Sized>(sync::Mutex<T>);

#[allow(dead_code)]
impl<T> Mutex<T> {
    #[inline]
    pub(crate) fn new(t: T) -> Mutex<T> {
        Mutex(sync::Mutex::new(t))
    }

    #[inline]
    pub(crate) const fn const_new(t: T) -> Mutex<T> {
        Mutex(sync::Mutex::new(t))
    }

    #[inline]
    pub(crate) fn lock(&self) -> MutexGuard<'_, T> {
        match self.0.lock() {
            Ok(guard) => guard,
            Err(p_err) => p_err.into_inner(),
        }
    }

    #[inline]
    pub(crate) fn try_lock(&self) -> Option<MutexGuard<'_, T>> {
        match self.0.try_lock() {
            Ok(guard) => Some(guard),
            Err(TryLockError::Poisoned(p_err)) => Some(p_err.into_inner()),
            Err(TryLockError::WouldBlock) => None,
        }
    }

    #[inline]
    pub(crate) fn get_mut(&mut self) -> &mut T {
        match self.0.get_mut() {
            Ok(val) => val,
            Err(p_err) => p_err.into_inner(),
        }
    }
}

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/tokio-1.43.0/src/loom/std/mutex.rs
wasmtime-28.0.0 ./ext/cargo-vendor/tokio-1.43.0/src/loom/std/mutex.rs
wasmtime-27.0.0 ./ext/cargo-vendor/tokio-1.41.1/src/loom/std/mutex.rs
wasmtime-26.0.0 ./ext/cargo-vendor/tokio-1.41.0/src/loom/std/mutex.rs
wasmtime-25.0.2 ./ext/cargo-vendor/tokio-1.40.0/src/loom/std/mutex.rs